github.com/pengwynn/gh@v1.0.1-0.20140118055701-14327ca3942e/features/fork.feature (about) 1 Feature: hub fork 2 Background: 3 Given I am in "dotfiles" git repo 4 And the "origin" remote has url "git://github.com/evilchelu/dotfiles.git" 5 And I am "mislav" on github.com with OAuth token "OTOKEN" 6 7 Scenario: Fork the repository 8 Given the GitHub API server: 9 """ 10 before do 11 unless request.env['HTTP_AUTHORIZATION'] == 'token OTOKEN' 12 status 401 13 json :message => "I haz fail!" 14 end 15 end 16 17 get('/repos/mislav/dotfiles') do 18 status 404 19 json :message => "I haz fail!" 20 end 21 22 post('/repos/evilchelu/dotfiles/forks') do 23 json :html_url => "https://github.com/mislav/coral/pull/12" 24 end 25 """ 26 When I successfully run `hub fork` 27 Then the output should contain exactly "new remote: mislav\n" 28 And "git remote add -f mislav git@github.com:mislav/dotfiles.git" should be run 29 And the url for "mislav" should be "git@github.com:mislav/dotfiles.git" 30 31 Scenario: --no-remote 32 Given the GitHub API server: 33 """ 34 post('/repos/evilchelu/dotfiles/forks') do 35 json :repo => "repo" 36 end 37 """ 38 When I successfully run `hub fork --no-remote` 39 Then there should be no output 40 And there should be no "mislav" remote 41 42 Scenario: Fork failed 43 Given the GitHub API server: 44 """ 45 post('/repos/evilchelu/dotfiles/forks') do 46 status 500 47 json(:error => "I haz fail!") 48 end 49 """ 50 When I run `hub fork` 51 Then the exit status should be 1 52 And the stderr should contain exactly: 53 """ 54 500 - Error: I haz fail!\n 55 """ 56 And there should be no "mislav" remote 57 58 Scenario: Unrelated fork already exists 59 Given the GitHub API server: 60 """ 61 get('/repos/mislav/dotfiles') { 62 halt 406 unless request.env['HTTP_ACCEPT'] == 'application/vnd.github.v3+json' 63 json :parent => { :html_url => 'https://github.com/unrelated/dotfiles' } 64 } 65 """ 66 When I run `hub fork` 67 Then the exit status should be 1 68 And the stderr should contain exactly: 69 """ 70 Error creating fork: mislav/dotfiles already exists on github.com\n 71 """ 72 And there should be no "mislav" remote 73 74 Scenario: Related fork already exists 75 Given the GitHub API server: 76 """ 77 get('/repos/mislav/dotfiles') { 78 json :parent => { :html_url => 'https://github.com/evilchelu/dotfiles' } 79 } 80 """ 81 When I run `hub fork` 82 Then the exit status should be 0 83 And the url for "mislav" should be "git@github.com:mislav/dotfiles.git" 84 85 Scenario: Invalid OAuth token 86 Given the GitHub API server: 87 """ 88 before do 89 unless request.env['HTTP_AUTHORIZATION'] == 'token OTOKEN' 90 halt 401, json(:message => "I haz fail!") 91 end 92 end 93 """ 94 And I am "mislav" on github.com with OAuth token "WRONGTOKEN" 95 When I run `hub fork` 96 Then the exit status should be 1 97 And the stderr should contain exactly: 98 """ 99 401 - I haz fail! 100 """ 101 102 Scenario: HTTPS is preferred 103 Given the GitHub API server: 104 """ 105 post('/repos/evilchelu/dotfiles/forks') { json :repo => 'repo' } 106 """ 107 And HTTPS is preferred 108 When I successfully run `hub fork` 109 Then the output should contain exactly "new remote: mislav\n" 110 And the url for "mislav" should be "https://github.com/mislav/dotfiles.git" 111 112 Scenario: Not in repo 113 Given the current dir is not a repo 114 When I run `hub fork` 115 Then the exit status should be 1 116 And the stderr should contain "Aborted: the origin remote doesn't point to a GitHub repository" 117 118 Scenario: Unknown host 119 Given the "origin" remote has url "git@git.my.org:evilchelu/dotfiles.git" 120 When I run `hub fork` 121 Then the exit status should be 1 122 And the stderr should contain: 123 """ 124 Aborted: the origin remote doesn't point to a GitHub repository 125 """ 126 127 Scenario: Enterprise fork 128 Given the GitHub API server: 129 """ 130 before do 131 unless request.env['HTTP_AUTHORIZATION'] == 'token FITOKEN' 132 status 401 133 json :error => 'error' 134 end 135 end 136 post('/api/v3/repos/evilchelu/dotfiles/forks') { json :repo => 'repo' } 137 """ 138 And the "origin" remote has url "git@git.my.org:evilchelu/dotfiles.git" 139 And I am "mislav" on git.my.org with OAuth token "FITOKEN" 140 And "git.my.org" is a whitelisted Enterprise host 141 When I successfully run `hub fork` 142 Then the url for "mislav" should be "git@git.my.org:mislav/dotfiles.git"