checkout.feature 9.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
Feature: hub checkout <PULLREQ-URL>
  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') {
14
        halt 415 unless request.accept?('application/vnd.github.v3+json')
15
        json :number => 77, :head => {
16
          :ref => "fixes",
17
          :repo => {
18
            :owner => { :login => "mislav" },
19
            :name => "jekyll",
20 21
            :private => false
          }
22 23 24 25 26 27
        }, :base => {
          :repo => {
            :name => 'jekyll',
            :html_url => 'https://github.com/mojombo/jekyll',
            :owner => { :login => "mojombo" },
          }
28
        }, :maintainer_can_modify => false
29 30
      }
      """
31
    When I successfully run `hub checkout -f https://github.com/mojombo/jekyll/pull/77 -q`
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
    Then "git fetch origin refs/pull/77/head:fixes" should be run
    And "git checkout -f fixes -q" should be run
    And "fixes" should merge "refs/pull/77/head" from remote "origin"

  Scenario: Head ref matches default branch
    Given the GitHub API server:
      """
      get('/repos/mojombo/jekyll/pulls/77') {
        json :number => 77, :head => {
          :ref => "master",
          :repo => {
            :owner => { :login => "mislav" },
            :name => "jekyll",
            :default_branch => "master",
            :private => false
          }
        }, :base => {
          :repo => {
            :name => 'jekyll',
            :html_url => 'https://github.com/mojombo/jekyll',
            :owner => { :login => "mojombo" },
          }
        }, :maintainer_can_modify => false
      }
      """
57
    When I successfully run `hub checkout https://github.com/mojombo/jekyll/pull/77`
58 59 60
    Then "git fetch origin refs/pull/77/head:mislav-master" should be run
    And "git checkout mislav-master" should be run
    And "mislav-master" should merge "refs/pull/77/head" from remote "origin"
61

62
  Scenario: No matching remotes for pull request base
63 64
    Given the GitHub API server:
      """
65
      get('/repos/mislav/jekyll/pulls/77') {
66
        json :number => 77, :base => {
67
          :repo => {
68 69
            :name => 'jekyll',
            :html_url => 'https://github.com/mislav/jekyll',
70
            :owner => { :login => "mislav" },
71 72 73 74
          }
        }
      }
      """
75 76 77
    When I run `hub checkout -f https://github.com/mislav/jekyll/pull/77 -q`
    Then the exit status should be 1
    And the stderr should contain exactly:
78
      """
79
      could not find a git remote for 'mislav/jekyll'\n
80 81
      """

82
  Scenario: Custom name for new branch
83 84 85
    Given the GitHub API server:
      """
      get('/repos/mojombo/jekyll/pulls/77') {
86
        json :number => 77, :head => {
87
          :ref => "fixes",
88
          :repo => {
89
            :name => "jekyll",
90
            :owner => { :login => "mislav" },
91
          }
92
        }, :base => {
93
          :repo => {
94 95 96
            :name => 'jekyll',
            :html_url => 'https://github.com/mojombo/jekyll',
            :owner => { :login => "mojombo" },
97
          }
98
        }, :maintainer_can_modify => false
99 100
      }
      """
101
    When I successfully run `hub checkout https://github.com/mojombo/jekyll/pull/77 fixes-from-mislav`
102
    Then "git fetch origin refs/pull/77/head:fixes-from-mislav" should be run
103
    And "git checkout fixes-from-mislav" should be run
N
Natalie Weizenbaum 已提交
104
    And "fixes-from-mislav" should merge "refs/pull/77/head" from remote "origin"
105 106 107 108 109

  Scenario: Same-repo
    Given the GitHub API server:
      """
      get('/repos/mojombo/jekyll/pulls/77') {
110
        json :number => 77, :head => {
111 112 113 114 115 116 117 118 119 120 121 122 123 124
          :ref => "fixes",
          :repo => {
            :name => "jekyll",
            :owner => { :login => "mojombo" },
          }
        }, :base => {
          :repo => {
            :name => "jekyll",
            :html_url => "https://github.com/mojombo/jekyll",
            :owner => { :login => "mojombo" },
          }
        }
      }
      """
125
    When I successfully run `hub checkout -f https://github.com/mojombo/jekyll/pull/77 -q`
126
    Then "git fetch origin +refs/heads/fixes:refs/remotes/origin/fixes" should be run
127 128
    And "git checkout -f -b fixes --no-track origin/fixes -q" should be run
    And "fixes" should merge "refs/heads/fixes" from remote "origin"
129 130 131 132 133

  Scenario: Same-repo with custom branch name
    Given the GitHub API server:
      """
      get('/repos/mojombo/jekyll/pulls/77') {
134
        json :number => 77, :head => {
135 136 137 138 139 140 141 142 143 144 145 146 147 148
          :ref => "fixes",
          :repo => {
            :name => "jekyll",
            :owner => { :login => "mojombo" },
          }
        }, :base => {
          :repo => {
            :name => "jekyll",
            :html_url => "https://github.com/mojombo/jekyll",
            :owner => { :login => "mojombo" },
          }
        }
      }
      """
149
    When I successfully run `hub checkout https://github.com/mojombo/jekyll/pull/77 mycustombranch`
150
    Then "git fetch origin +refs/heads/fixes:refs/remotes/origin/fixes" should be run
151 152
    And "git checkout -b mycustombranch --no-track origin/fixes" should be run
    And "mycustombranch" should merge "refs/heads/fixes" from remote "origin"
153 154 155 156 157

  Scenario: Unavailable fork
    Given the GitHub API server:
      """
      get('/repos/mojombo/jekyll/pulls/77') {
158
        json :number => 77, :head => {
159 160 161 162 163 164 165 166 167 168 169
          :ref => "fixes",
          :repo => nil
        }, :base => {
          :repo => {
            :name => "jekyll",
            :html_url => "https://github.com/mojombo/jekyll",
            :owner => { :login => "mojombo" },
          }
        }
      }
      """
170
    When I successfully run `hub checkout https://github.com/mojombo/jekyll/pull/77`
171 172 173
    Then "git fetch origin refs/pull/77/head:fixes" should be run
    And "git checkout fixes" should be run
    And "fixes" should merge "refs/pull/77/head" from remote "origin"
174

175 176 177 178
  Scenario: Reuse existing remote for head branch
    Given the GitHub API server:
      """
      get('/repos/mojombo/jekyll/pulls/77') {
179
        json :number => 77, :head => {
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
          :ref => "fixes",
          :repo => {
            :owner => { :login => "mislav" },
            :name => "jekyll",
            :private => false
          }
        }, :base => {
          :repo => {
            :name => 'jekyll',
            :html_url => 'https://github.com/mojombo/jekyll',
            :owner => { :login => "mojombo" },
          }
        }
      }
      """
    And the "mislav" remote has url "git://github.com/mislav/jekyll.git"
196
    When I successfully run `hub checkout -f https://github.com/mojombo/jekyll/pull/77 -q`
197
    Then "git fetch mislav +refs/heads/fixes:refs/remotes/mislav/fixes" should be run
198 199
    And "git checkout -f -b fixes --no-track mislav/fixes -q" should be run
    And "fixes" should merge "refs/heads/fixes" from remote "mislav"
200 201 202 203 204

  Scenario: Reuse existing remote and branch
    Given the GitHub API server:
      """
      get('/repos/mojombo/jekyll/pulls/77') {
205
        json :number => 77, :head => {
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
          :ref => "fixes",
          :repo => {
            :owner => { :login => "mislav" },
            :name => "jekyll",
            :private => false
          }
        }, :base => {
          :repo => {
            :name => 'jekyll',
            :html_url => 'https://github.com/mojombo/jekyll',
            :owner => { :login => "mojombo" },
          }
        }
      }
      """
    And the "mislav" remote has url "git://github.com/mislav/jekyll.git"
    And I am on the "fixes" branch
223
    When I successfully run `hub checkout -f https://github.com/mojombo/jekyll/pull/77 -q`
224 225 226
    Then "git fetch mislav +refs/heads/fixes:refs/remotes/mislav/fixes" should be run
    And "git checkout -f fixes -q" should be run
    And "git merge --ff-only refs/remotes/mislav/fixes" should be run
227 228 229 230 231

  Scenario: Modifiable fork
    Given the GitHub API server:
      """
      get('/repos/mojombo/jekyll/pulls/77') {
232
        json :number => 77, :head => {
233 234 235 236
          :ref => "fixes",
          :repo => {
            :owner => { :login => "mislav" },
            :name => "jekyll",
N
Natalie Weizenbaum 已提交
237
            :html_url => "https://github.com/mislav/jekyll.git",
238 239 240 241 242 243 244 245 246 247 248
            :private => false
          },
        }, :base => {
          :repo => {
            :name => 'jekyll',
            :html_url => 'https://github.com/mojombo/jekyll',
            :owner => { :login => "mojombo" },
          }
        }, :maintainer_can_modify => true
      }
      """
249
    When I successfully run `hub checkout -f https://github.com/mojombo/jekyll/pull/77 -q`
250 251 252
    Then "git fetch origin refs/pull/77/head:fixes" should be run
    And "git checkout -f fixes -q" should be run
    And "fixes" should merge "refs/heads/fixes" from remote "git@github.com:mislav/jekyll.git"
N
Natalie Weizenbaum 已提交
253 254 255 256 257

  Scenario: Modifiable fork with HTTPS
    Given the GitHub API server:
      """
      get('/repos/mojombo/jekyll/pulls/77') {
258
        json :number => 77, :head => {
N
Natalie Weizenbaum 已提交
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275
          :ref => "fixes",
          :repo => {
            :owner => { :login => "mislav" },
            :name => "jekyll",
            :html_url => "https://github.com/mislav/jekyll.git",
            :private => false
          },
        }, :base => {
          :repo => {
            :name => 'jekyll',
            :html_url => 'https://github.com/mojombo/jekyll',
            :owner => { :login => "mojombo" },
          }
        }, :maintainer_can_modify => true
      }
      """
    And HTTPS is preferred
276
    When I successfully run `hub checkout -f https://github.com/mojombo/jekyll/pull/77 -q`
277 278 279
    Then "git fetch origin refs/pull/77/head:fixes" should be run
    And "git checkout -f fixes -q" should be run
    And "fixes" should merge "refs/heads/fixes" from remote "https://github.com/mislav/jekyll.git"