diff --git a/features/checkout.feature b/features/checkout.feature new file mode 100644 index 0000000000000000000000000000000000000000..e1e11aad3b87f645ce3b184d586fb0660eb81b32 --- /dev/null +++ b/features/checkout.feature @@ -0,0 +1,80 @@ +Feature: hub checkout + Background: + Given I am in "git://github.com/mojombo/jekyll.git" git repo + And I am "mislav" on github.com with OAuth token "OTOKEN" + + Scenario: Unchanged command + When I run `hub checkout master` + Then "git checkout master" should be run + + Scenario: Checkout a pull request + Given the GitHub API server: + """ + get('/repos/mojombo/jekyll/pulls/77') { + json :head => { + :label => 'mislav:fixes', + :repo => { :private => false } + } + } + """ + When I run `hub checkout -f https://github.com/mojombo/jekyll/pull/77 -q` + Then "git remote add -f -t fixes mislav git://github.com/mislav/jekyll.git" should be run + And "git checkout -f --track -B mislav-fixes mislav/fixes -q" should be run + + Scenario: Custom name for new branch + Given the GitHub API server: + """ + get('/repos/mojombo/jekyll/pulls/77') { + json :head => { + :label => 'mislav:fixes', + :repo => { :private => false } + } + } + """ + When I run `hub checkout https://github.com/mojombo/jekyll/pull/77 fixes-from-mislav` + Then "git remote add -f -t fixes mislav git://github.com/mislav/jekyll.git" should be run + And "git checkout --track -B fixes-from-mislav mislav/fixes" should be run + + Scenario: Private pull request + Given the GitHub API server: + """ + get('/repos/mojombo/jekyll/pulls/77') { + json :head => { + :label => 'mislav:fixes', + :repo => { :private => true } + } + } + """ + When I run `hub checkout -f https://github.com/mojombo/jekyll/pull/77 -q` + Then "git remote add -f -t fixes mislav git@github.com:mislav/jekyll.git" should be run + And "git checkout -f --track -B mislav-fixes mislav/fixes -q" should be run + + Scenario: Custom name for new branch + Given the GitHub API server: + """ + get('/repos/mojombo/jekyll/pulls/77') { + json :head => { + :label => 'mislav:fixes', + :repo => { :private => false } + } + } + """ + When I run `hub checkout https://github.com/mojombo/jekyll/pull/77 fixes-from-mislav` + Then "git remote add -f -t fixes mislav git://github.com/mislav/jekyll.git" should be run + And "git checkout --track -B fixes-from-mislav mislav/fixes" should be run + + Scenario: Remote for user already exists + Given the GitHub API server: + """ + get('/repos/mojombo/jekyll/pulls/77') { + json :head => { + :label => 'mislav:fixes', + :repo => { :private => false } + } + } + """ + And the "mislav" remote has url "git://github.com/mislav/jekyll.git" + When I run `hub checkout https://github.com/mojombo/jekyll/pull/77` + Then "git remote set-branches --add mislav fixes" should be run + And "git fetch mislav +refs/heads/fixes:refs/remotes/mislav/fixes" should be run + And "git checkout --track -B mislav-fixes mislav/fixes" should be run diff --git a/test/hub_test.rb b/test/hub_test.rb index bb9d7b58fb1b9fc37d66d71dad6099c69afb3bfd..e5981b102191beef2493902dce57381aa968d5b3 100644 --- a/test/hub_test.rb +++ b/test/hub_test.rb @@ -444,49 +444,6 @@ class HubTest < Test::Unit::TestCase assert_output expected, "pull-request hereyougo -b feature -f" end - def test_checkout_no_changes - assert_forwarded "checkout master" - end - - def test_checkout_pullrequest - stub_request(:get, "https://api.github.com/repos/defunkt/hub/pulls/73"). - to_return(:body => mock_pull_response('blueyed:feature')) - - assert_commands 'git remote add -f -t feature blueyed git://github.com/blueyed/hub.git', - 'git checkout -f --track -B blueyed-feature blueyed/feature -q', - "checkout -f https://github.com/defunkt/hub/pull/73/files -q" - end - - def test_checkout_private_pullrequest - stub_request(:get, "https://api.github.com/repos/defunkt/hub/pulls/73"). - to_return(:body => mock_pull_response('blueyed:feature', :private)) - - assert_commands 'git remote add -f -t feature blueyed git@github.com:blueyed/hub.git', - 'git checkout --track -B blueyed-feature blueyed/feature', - "checkout https://github.com/defunkt/hub/pull/73/files" - end - - def test_checkout_pullrequest_custom_branch - stub_request(:get, "https://api.github.com/repos/defunkt/hub/pulls/73"). - to_return(:body => mock_pull_response('blueyed:feature')) - - assert_commands 'git remote add -f -t feature blueyed git://github.com/blueyed/hub.git', - 'git checkout --track -B review blueyed/feature', - "checkout https://github.com/defunkt/hub/pull/73/files review" - end - - def test_checkout_pullrequest_existing_remote - stub_command_output 'remote', "origin\nblueyed" - - stub_request(:get, "https://api.github.com/repos/defunkt/hub/pulls/73"). - to_return(:body => mock_pull_response('blueyed:feature')) - - assert_commands 'git remote set-branches --add blueyed feature', - 'git fetch blueyed +refs/heads/feature:refs/remotes/blueyed/feature', - 'git checkout --track -B blueyed-feature blueyed/feature', - "checkout https://github.com/defunkt/hub/pull/73/files" - end - def test_version out = hub('--version') assert_includes "git version 1.7.0.4", out