From 2a02c083755db0b783e6969b6e1c87d90ddd3f66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohnic=CC=81?= Date: Fri, 2 Mar 2012 14:13:02 +0100 Subject: [PATCH] fix `pull-request` from branch tracking another local branch In this case, pretend there is no upstream configuration at all. Closes #141 --- lib/hub/commands.rb | 6 +++++- lib/hub/context.rb | 2 +- test/hub_test.rb | 19 +++++++++++++++---- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/lib/hub/commands.rb b/lib/hub/commands.rb index a5769c27..b9ed7fbf 100644 --- a/lib/hub/commands.rb +++ b/lib/hub/commands.rb @@ -108,7 +108,11 @@ module Hub options[:base] ||= master_branch.short_name if tracked_branch = options[:head].nil? && current_branch.upstream - if base_project == head_project and tracked_branch.short_name == options[:base] + if !tracked_branch.remote? + # The current branch is tracking another local branch. Pretend there is + # no upstream configuration at all. + tracked_branch = nil + elsif base_project == head_project and tracked_branch.short_name == options[:base] $stderr.puts "Aborted: head branch is the same as base (#{options[:base].inspect})" warn "(use `-h ` to specify an explicit pull request head)" abort diff --git a/lib/hub/context.rb b/lib/hub/context.rb index 45b902ce..4233e910 100644 --- a/lib/hub/context.rb +++ b/lib/hub/context.rb @@ -130,7 +130,7 @@ module Hub end def upstream_project - if branch = current_branch and upstream = branch.upstream + if branch = current_branch and upstream = branch.upstream and upstream.remote? remote = remote_by_name upstream.remote_name remote.project end diff --git a/test/hub_test.rb b/test/hub_test.rb index a791a2c9..fc126b6c 100644 --- a/test/hub_test.rb +++ b/test/hub_test.rb @@ -839,7 +839,6 @@ class HubTest < Test::Unit::TestCase def test_pullrequest_from_tracking_branch stub_branch('refs/heads/feature') stub_tracking('feature', 'mislav', 'yay-feature') - stub_command_output "rev-list --cherry-pick --right-only --no-merges mislav/master...", nil stub_request(:post, "https://#{auth}github.com/api/v2/json/pulls/defunkt/hub"). with(:body => { 'pull' => {'base' => "master", 'head' => "mislav:yay-feature", 'title' => "hereyougo"} }). @@ -849,6 +848,18 @@ class HubTest < Test::Unit::TestCase assert_output expected, "pull-request hereyougo -f" end + def test_pullrequest_from_branch_tracking_local + stub_branch('refs/heads/feature') + stub_tracking('feature', 'refs/heads/master') + + stub_request(:post, "https://#{auth}github.com/api/v2/json/pulls/defunkt/hub"). + with(:body => { 'pull' => {'base' => "master", 'head' => "tpw:feature", 'title' => "hereyougo"} }). + to_return(:body => mock_pullreq_response(1)) + + expected = "https://github.com/defunkt/hub/pull/1\n" + assert_output expected, "pull-request hereyougo -f" + end + def test_pullrequest_enterprise_no_tracking stub_hub_host('git.my.org') stub_repo_url('git@git.my.org:defunkt/hub.git') @@ -1287,13 +1298,13 @@ config stub_command_output 'symbolic-ref -q HEAD', value end - def stub_tracking(from, remote_name, remote_branch) + def stub_tracking(from, upstream, remote_branch = nil) stub_command_output "rev-parse --symbolic-full-name #{from}@{upstream}", - remote_branch ? "refs/remotes/#{remote_name}/#{remote_branch}" : nil + remote_branch ? "refs/remotes/#{upstream}/#{remote_branch}" : upstream end def stub_tracking_nothing(from = 'master') - stub_tracking(from, nil, nil) + stub_tracking(from, nil) end def stub_remotes_group(name, value)