From 70a62f8adef96d1eb8a3ed5528f72664fb4b092e Mon Sep 17 00:00:00 2001 From: Luismi Cavalle Date: Sat, 23 Mar 2013 17:14:46 -0300 Subject: [PATCH] friendly error for `pull-request` in detached HEAD --- features/pull_request.feature | 7 +++++++ features/steps.rb | 6 ++++++ lib/hub/commands.rb | 4 ++++ 3 files changed, 17 insertions(+) diff --git a/features/pull_request.feature b/features/pull_request.feature index de315475..2842f021 100644 --- a/features/pull_request.feature +++ b/features/pull_request.feature @@ -3,6 +3,13 @@ Feature: hub pull-request Given I am in "dotfiles" git repo And I am "mislav" on github.com with OAuth token "OTOKEN" + Scenario: Detached HEAD + Given the "origin" remote has url "git://github.com/mislav/coral.git" + And I am in detached HEAD + When I run `hub pull-request` + Then the stderr should contain "Aborted: not currently on any branch.\n" + And the exit status should be 1 + Scenario: Non-GitHub repo Given the "origin" remote has url "mygh:Manganeez/repo.git" When I run `hub pull-request` diff --git a/features/steps.rb b/features/steps.rb index ecfd17cb..dc5e007b 100644 --- a/features/steps.rb +++ b/features/steps.rb @@ -69,6 +69,12 @@ Given /^I am on the "([^"]+)" branch(?: with upstream "([^"]+)")?$/ do |name, up run_silent %(git checkout --quiet -B #{name} --track #{upstream}) end +Given /^I am in detached HEAD$/ do + empty_commit + empty_commit + run_silent %(git checkout HEAD^) +end + Given /^the current dir is not a repo$/ do in_current_dir do FileUtils.rm_rf '.git' diff --git a/lib/hub/commands.rb b/lib/hub/commands.rb index 68c9f608..4e661886 100644 --- a/lib/hub/commands.rb +++ b/lib/hub/commands.rb @@ -81,6 +81,10 @@ module Hub base_project = local_repo.main_project head_project = local_repo.current_project + unless current_branch + abort "Aborted: not currently on any branch." + end + unless base_project abort "Aborted: the origin remote doesn't point to a GitHub repository." end -- GitLab