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

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

Closes #141
This commit is contained in:
Mislav Marohnić 2012-03-02 14:13:02 +01:00
Родитель 1e45ad9e16
Коммит 2a02c08375
3 изменённых файлов: 21 добавлений и 6 удалений

Просмотреть файл

@ -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 <branch>` to specify an explicit pull request head)"
abort

Просмотреть файл

@ -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

Просмотреть файл

@ -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)