提交 e645f9aa 编写于 作者: M Mislav Marohnić

pull-request: detect default branch for project

This is usually "master" but for e.g. git-flow projects it's "develop".
GitHub has an API field for the default branch but I avoided having to
hit the API and instead read from the "head" of the origin remote.

  git rev-parse --symbolic-full-name origin
  #=> refs/remotes/origin/develop

The "head" of the remote seems to be set at clone time by default, and
can be manually set with:

  git remote set-head origin develop

The pull-request command now detects this and sets the default branch as
the pull request base instead of always assuming "master" at origin.

Fixes #154, closes #326
上级 e4add4c8
......@@ -255,6 +255,20 @@ Feature: hub pull-request
When I successfully run `hub pull-request -b develop -m message`
Then the output should contain exactly "the://url\n"
Scenario: Implicit base by detecting main branch
Given the default branch for "origin" is "develop"
And I am on the "master" branch
Given the GitHub API server:
"""
post('/repos/mislav/coral/pulls') {
assert :base => 'develop',
:head => 'mislav:master'
json :html_url => "the://url"
}
"""
When I successfully run `hub pull-request -m message`
Then the output should contain exactly "the://url\n"
Scenario: Explicit base with owner
Given I am on the "master" branch
Given the GitHub API server:
......
......@@ -74,6 +74,16 @@ Given(/^I am on the "([^"]+)" branch(?: with upstream "([^"]+)")?$/) do |name, u
run_silent %(git checkout --quiet -B #{name} --track #{upstream})
end
Given(/^the default branch for "([^"]+)" is "([^"]+)"$/) do |remote, branch|
empty_commit
ref_file = ".git/refs/remotes/#{remote}/#{branch}"
in_current_dir do
FileUtils.mkdir_p File.dirname(ref_file)
FileUtils.cp '.git/refs/heads/master', ref_file
end
run_silent %(git remote set-head #{remote} #{branch})
end
Given(/^I am in detached HEAD$/) do
empty_commit
empty_commit
......
......@@ -159,7 +159,10 @@ module Hub
end
def master_branch
Branch.new self, 'refs/heads/master'
if remote = origin_remote
default_branch = git_command("rev-parse --symbolic-full-name #{remote}")
end
Branch.new(self, default_branch || 'refs/heads/master')
end
def remotes
......
......@@ -260,6 +260,7 @@ class HubTest < Test::Unit::TestCase
def test_pullrequest_from_branch_tracking_local
stub_branch('refs/heads/feature')
stub_tracking('feature', 'refs/heads/master')
stub_command_output('rev-parse --symbolic-full-name origin', 'refs/remotes/origin/master')
stub_request(:post, "https://api.github.com/repos/defunkt/hub/pulls").
with(:body => {'base' => "master", 'head' => "tpw:feature", 'title' => "hereyougo" }).
......@@ -274,6 +275,7 @@ class HubTest < Test::Unit::TestCase
stub_repo_url('git@git.my.org:defunkt/hub.git')
stub_branch('refs/heads/feature')
stub_tracking_nothing('feature')
stub_command_output('rev-parse --symbolic-full-name origin', 'refs/remotes/origin/master')
stub_command_output "rev-list --cherry-pick --right-only --no-merges origin/feature...", nil
edit_hub_config do |data|
data['git.my.org'] = [{'user'=>'myfiname', 'oauth_token' => 'FITOKEN'}]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册