checkout.feature 9.3 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 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 57 58 59 60
    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
      }
      """
    When I run `hub checkout https://github.com/mojombo/jekyll/pull/77`
    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 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 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 125 126 127 128 129 130 131 132
          :ref => "fixes",
          :repo => {
            :name => "jekyll",
            :owner => { :login => "mojombo" },
          }
        }, :base => {
          :repo => {
            :name => "jekyll",
            :html_url => "https://github.com/mojombo/jekyll",
            :owner => { :login => "mojombo" },
          }
        }
      }
      """
    When I run `hub checkout -f https://github.com/mojombo/jekyll/pull/77 -q`
    Then "git fetch origin +refs/heads/fixes:refs/remotes/origin/fixes" should be run
    And "git checkout -f -b fixes --track origin/fixes -q" should be run

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

  Scenario: Unavailable fork
    Given the GitHub API server:
      """
      get('/repos/mojombo/jekyll/pulls/77') {
156
        json :number => 77, :head => {
157 158 159 160 161 162 163 164 165 166 167 168
          :ref => "fixes",
          :repo => nil
        }, :base => {
          :repo => {
            :name => "jekyll",
            :html_url => "https://github.com/mojombo/jekyll",
            :owner => { :login => "mojombo" },
          }
        }
      }
      """
    When I run `hub checkout https://github.com/mojombo/jekyll/pull/77`
169 170 171
    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"
172

173 174 175 176
  Scenario: Reuse existing remote for head branch
    Given the GitHub API server:
      """
      get('/repos/mojombo/jekyll/pulls/77') {
177
        json :number => 77, :head => {
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
          :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"
    When I run `hub checkout -f https://github.com/mojombo/jekyll/pull/77 -q`
    Then "git fetch mislav +refs/heads/fixes:refs/remotes/mislav/fixes" should be run
    And "git checkout -f -b fixes --track mislav/fixes -q" should be run

  Scenario: Reuse existing remote and branch
    Given the GitHub API server:
      """
      get('/repos/mojombo/jekyll/pulls/77') {
202
        json :number => 77, :head => {
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
          :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
    When I run `hub checkout -f https://github.com/mojombo/jekyll/pull/77 -q`
    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
224 225 226 227 228

  Scenario: Modifiable fork
    Given the GitHub API server:
      """
      get('/repos/mojombo/jekyll/pulls/77') {
229
        json :number => 77, :head => {
230 231 232 233
          :ref => "fixes",
          :repo => {
            :owner => { :login => "mislav" },
            :name => "jekyll",
N
Natalie Weizenbaum 已提交
234
            :html_url => "https://github.com/mislav/jekyll.git",
235 236 237 238 239 240 241 242 243 244 245 246
            :private => false
          },
        }, :base => {
          :repo => {
            :name => 'jekyll',
            :html_url => 'https://github.com/mojombo/jekyll',
            :owner => { :login => "mojombo" },
          }
        }, :maintainer_can_modify => true
      }
      """
    When I run `hub checkout -f https://github.com/mojombo/jekyll/pull/77 -q`
247 248 249
    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 已提交
250 251 252 253 254

  Scenario: Modifiable fork with HTTPS
    Given the GitHub API server:
      """
      get('/repos/mojombo/jekyll/pulls/77') {
255
        json :number => 77, :head => {
N
Natalie Weizenbaum 已提交
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273
          :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
    When I run `hub checkout -f https://github.com/mojombo/jekyll/pull/77 -q`
274 275 276
    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"