diff --git a/features/pull_request.feature b/features/pull_request.feature index de315475b84a863f2790f7895cfae145486ea501..2842f02161cab09a0bba33bc06f347aa74717bdf 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 ecfd17cb4a5d5910aeb80b67d9b5927530d94c6d..dc5e007bf7b85c8fac93dfb05452351269420b30 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 68c9f608d16a43ff9f06a4614ce128c0ae21d390..4e66188623f11b91d68f51b3d421bef53296c27e 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