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

Merge pull request #598 from github/more-cukes

Port `cherry-pick`, `pull-request` tests to cukes
Feature: hub cherry-pick
Background:
Given I am in "git://github.com/rtomayko/ronn.git" git repo
And I am "mislav" on github.com with OAuth token "OTOKEN"
Scenario: Unchanged
When I run `hub cherry-pick a319d88`
Then the git command should be unchanged
Scenario: From GitHub commit URL
When I run `hub cherry-pick https://github.com/rtomayko/ronn/commit/a319d88#comments`
Then "git fetch origin" should be run
And "git cherry-pick a319d88" should be run
Scenario: From fork that has existing remote
Given the "mislav" remote has url "git@github.com:mislav/ronn.git"
When I run `hub cherry-pick https://github.com/mislav/ronn/commit/a319d88`
Then "git fetch mislav" should be run
And "git cherry-pick a319d88" should be run
Scenario: Using GitHub owner@SHA notation
Given the "mislav" remote has url "git@github.com:mislav/ronn.git"
When I run `hub cherry-pick mislav@a319d88`
Then "git fetch mislav" should be run
And "git cherry-pick a319d88" should be run
Scenario: Using GitHub owner@SHA notation that is too short
When I run `hub cherry-pick mislav@a319`
Then the git command should be unchanged
Scenario: Unsupported GitHub owner/repo@SHA notation
When I run `hub cherry-pick mislav/ronn@a319d88`
Then the git command should be unchanged
Scenario: Skips processing if `-m/--mainline` is specified
When I run `hub cherry-pick -m 42 mislav@a319d88`
Then the git command should be unchanged
When I run `hub cherry-pick --mainline 42 mislav@a319d88`
Then the git command should be unchanged
Scenario: Using GitHub owner@SHA notation with remote add
When I run `hub cherry-pick mislav@a319d88`
Then "git remote add -f mislav git://github.com/mislav/ronn.git" should be run
And "git cherry-pick a319d88" should be run
Scenario: From fork that doesn't have a remote
When I run `hub cherry-pick https://github.com/jingweno/ronn/commit/a319d88`
Then "git remote add -f jingweno git://github.com/jingweno/ronn.git" should be run
And "git cherry-pick a319d88" should be run
...@@ -465,7 +465,25 @@ Feature: hub pull-request ...@@ -465,7 +465,25 @@ Feature: hub pull-request
And "git.my.org" is a whitelisted Enterprise host And "git.my.org" is a whitelisted Enterprise host
Given the GitHub API server: Given the GitHub API server:
""" """
post('/api/v3/repos/mislav/coral/pulls') { post('/api/v3/repos/mislav/coral/pulls', :host_name => 'git.my.org') {
assert :base => 'master',
:head => 'mislav:master'
json :html_url => "the://url"
}
"""
When I successfully run `hub pull-request -m enterprisey`
Then the output should contain exactly "the://url\n"
Scenario: Enterprise remote witch matching branch but no tracking
Given the "origin" remote has url "git@git.my.org:mislav/coral.git"
And I am "mislav" on git.my.org with OAuth token "FITOKEN"
And "git.my.org" is a whitelisted Enterprise host
And I am on the "feature" branch pushed to "origin/feature"
Given the GitHub API server:
"""
post('/api/v3/repos/mislav/coral/pulls', :host_name => 'git.my.org') {
assert :base => 'master',
:head => 'mislav:feature'
json :html_url => "the://url" json :html_url => "the://url"
} }
""" """
...@@ -528,3 +546,17 @@ Feature: hub pull-request ...@@ -528,3 +546,17 @@ Feature: hub pull-request
""" """
When I successfully run `hub pull-request -o -m hereyougo` When I successfully run `hub pull-request -o -m hereyougo`
Then "open the://url" should be run Then "open the://url" should be run
Scenario: Current branch is tracking local branch
Given git "push.default" is set to "upstream"
And I am on the "feature" branch with upstream "refs/heads/master"
Given the GitHub API server:
"""
post('/repos/mislav/coral/pulls') {
assert :base => 'master',
:head => 'mislav:feature'
json :html_url => "the://url"
}
"""
When I successfully run `hub pull-request -m hereyougo`
Then the output should contain exactly "the://url\n"
...@@ -85,11 +85,15 @@ end ...@@ -85,11 +85,15 @@ end
Given(/^I am on the "([^"]+)" branch(?: (pushed to|with upstream) "([^"]+)")?$/) do |name, type, upstream| Given(/^I am on the "([^"]+)" branch(?: (pushed to|with upstream) "([^"]+)")?$/) do |name, type, upstream|
empty_commit empty_commit
if upstream if upstream
full_upstream = ".git/refs/remotes/#{upstream}" if upstream =~ /^refs\//
full_upstream = ".git/#{upstream}"
else
full_upstream = ".git/refs/remotes/#{upstream}"
end
in_current_dir do in_current_dir do
FileUtils.mkdir_p File.dirname(full_upstream) FileUtils.mkdir_p File.dirname(full_upstream)
FileUtils.cp '.git/refs/heads/master', full_upstream FileUtils.cp '.git/refs/heads/master', full_upstream
end end unless upstream == 'refs/heads/master'
end end
track = type == 'pushed to' ? '--no-track' : '--track' track = type == 'pushed to' ? '--no-track' : '--track'
run_silent %(git checkout --quiet -B #{name} #{track} #{upstream}) run_silent %(git checkout --quiet -B #{name} #{track} #{upstream})
......
...@@ -116,83 +116,6 @@ class HubTest < Minitest::Test ...@@ -116,83 +116,6 @@ class HubTest < Minitest::Test
WebMock.reset! WebMock.reset!
end end
def test_cherry_pick
assert_forwarded "cherry-pick a319d88"
end
def test_cherry_pick_url
url = 'http://github.com/mislav/hub/commit/a319d88'
assert_commands "git fetch mislav", "git cherry-pick a319d88", "cherry-pick #{url}"
end
def test_cherry_pick_url_with_fragment
url = 'http://github.com/mislav/hub/commit/abcdef0123456789#comments'
assert_commands "git fetch mislav", "git cherry-pick abcdef0123456789", "cherry-pick #{url}"
end
def test_cherry_pick_url_with_remote_add
url = 'https://github.com/xoebus/hub/commit/a319d88'
assert_commands "git remote add -f xoebus git://github.com/xoebus/hub.git",
"git cherry-pick a319d88",
"cherry-pick #{url}"
end
def test_cherry_pick_origin_url
url = 'https://github.com/defunkt/hub/commit/a319d88'
assert_commands "git fetch origin", "git cherry-pick a319d88", "cherry-pick #{url}"
end
def test_cherry_pick_github_user_notation
assert_commands "git fetch mislav", "git cherry-pick 368af20", "cherry-pick mislav@368af20"
end
def test_cherry_pick_github_user_repo_notation
# not supported
assert_forwarded "cherry-pick mislav/hubbub@a319d88"
end
def test_cherry_pick_github_notation_too_short
assert_forwarded "cherry-pick mislav@a319"
end
def test_cherry_pick_github_notation_with_remote_add
assert_commands "git remote add -f xoebus git://github.com/xoebus/hub.git",
"git cherry-pick a319d88",
"cherry-pick xoebus@a319d88"
end
def test_pullrequest_from_branch_tracking_local
stub_config_value 'push.default', 'upstream'
stub_branch('refs/heads/feature')
stub_tracking('feature', 'refs/heads/master')
stub_request(:post, "https://api.github.com/repos/defunkt/hub/pulls").
with(:body => {'base' => "master", 'head' => "defunkt:feature", 'title' => "hereyougo" }).
to_return(:body => mock_pullreq_response(1))
expected = "https://github.com/defunkt/hub/pull/1\n"
assert_output expected, "pull-request -m 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')
stub_branch('refs/heads/feature')
stub_remote_branch('origin/feature')
stub_tracking_nothing('feature')
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'}]
end
stub_request(:post, "https://git.my.org/api/v3/repos/defunkt/hub/pulls").
with(:body => {'base' => "master", 'head' => "defunkt:feature", 'title' => "hereyougo" }).
to_return(:body => mock_pullreq_response(1, 'api/v3/defunkt/hub', 'git.my.org'))
expected = "https://git.my.org/api/v3/defunkt/hub/pull/1\n"
assert_output expected, "pull-request -m hereyougo -f"
end
def test_pullrequest_alias def test_pullrequest_alias
out = hub('e-note') out = hub('e-note')
assert_equal hub('pull-request'), out assert_equal hub('pull-request'), out
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册