Skip to content
Browse files

fix `pull-request` from branch tracking another local branch

In this case, pretend there is no upstream configuration at all.

Closes #141
  • Loading branch information...
1 parent 1e45ad9 commit 2a02c083755db0b783e6969b6e1c87d90ddd3f66 @mislav mislav committed
Showing with 21 additions and 6 deletions.
  1. +5 −1 lib/hub/commands.rb
  2. +1 −1 lib/hub/context.rb
  3. +15 −4 test/hub_test.rb
View
6 lib/hub/commands.rb
@@ -108,7 +108,11 @@ def pull_request(args)
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 <branch>` to specify an explicit pull request head)"
abort
View
2 lib/hub/context.rb
@@ -130,7 +130,7 @@ def main_project
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
View
19 test/hub_test.rb
@@ -839,7 +839,6 @@ def test_pullrequest_from_branch
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 @@ def test_pullrequest_from_tracking_branch
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 @@ def stub_branch(value)
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)

0 comments on commit 2a02c08

Please sign in to comment.
Something went wrong with that request. Please try again.