checkout.feature 7.8 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 406 unless request.env['HTTP_ACCEPT'] == 'application/vnd.github.v3+json;charset=utf-8'
15
        json :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
    Then "git fetch origin refs/pull/77/head:mislav-fixes" should be run
33 34
    And "git config branch.mislav-fixes.remote origin" should be run
    And "git config branch.mislav-fixes.merge refs/pull/77/head" should be run
35
    And "git checkout -f mislav-fixes -q" should be run
36

37
  Scenario: No matching remotes for pull request base
38 39
    Given the GitHub API server:
      """
40 41
      get('/repos/mislav/jekyll/pulls/77') {
        json :base => {
42
          :repo => {
43 44
            :name => 'jekyll',
            :html_url => 'https://github.com/mislav/jekyll',
45
            :owner => { :login => "mislav" },
46 47 48 49
          }
        }
      }
      """
50 51 52
    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:
53
      """
54
      could not find git remote for mislav/jekyll\n
55 56
      """

57
  Scenario: Custom name for new branch
58 59 60 61
    Given the GitHub API server:
      """
      get('/repos/mojombo/jekyll/pulls/77') {
        json :head => {
62
          :ref => "fixes",
63
          :repo => {
64
            :name => "jekyll",
65
            :owner => { :login => "mislav" },
66
          }
67
        }, :base => {
68
          :repo => {
69 70 71
            :name => 'jekyll',
            :html_url => 'https://github.com/mojombo/jekyll',
            :owner => { :login => "mojombo" },
72
          }
73
        }, :maintainer_can_modify => false
74 75
      }
      """
76
    When I run `hub checkout https://github.com/mojombo/jekyll/pull/77 fixes-from-mislav`
77
    Then "git fetch origin refs/pull/77/head:fixes-from-mislav" should be run
78 79
    And "git config branch.fixes-from-mislav.remote origin" should be run
    And "git config branch.fixes-from-mislav.merge refs/pull/77/head" should be run
80
    And "git checkout fixes-from-mislav" should be run
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126

  Scenario: Same-repo
    Given the GitHub API server:
      """
      get('/repos/mojombo/jekyll/pulls/77') {
        json :head => {
          :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') {
        json :head => {
          :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
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144

  Scenario: Unavailable fork
    Given the GitHub API server:
      """
      get('/repos/mojombo/jekyll/pulls/77') {
        json :head => {
          :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`
145
    Then "git fetch origin refs/pull/77/head:pr-77" should be run
146 147
    And "git config branch.pr-77.remote origin" should be run
    And "git config branch.pr-77.merge refs/pull/77/head" should be run
148
    And "git checkout pr-77" should be run
149

150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
  Scenario: Reuse existing remote for head branch
    Given the GitHub API server:
      """
      get('/repos/mojombo/jekyll/pulls/77') {
        json :head => {
          :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') {
        json :head => {
          :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
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228

  Scenario: Modifiable fork
    Given the GitHub API server:
      """
      get('/repos/mojombo/jekyll/pulls/77') {
        halt 406 unless request.env['HTTP_ACCEPT'] == 'application/vnd.github.v3+json;charset=utf-8'
        json :head => {
          :ref => "fixes",
          :repo => {
            :owner => { :login => "mislav" },
            :name => "jekyll",
            :ssh_url => "git@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
      }
      """
    When I run `hub checkout -f https://github.com/mojombo/jekyll/pull/77 -q`
    Then "git fetch origin refs/pull/77/head:mislav-fixes" should be run
    And "git config branch.mislav-fixes.remote git@github.com:mislav/jekyll.git" should be run
    And "git config branch.mislav-fixes.merge refs/heads/fixes" should be run
    And "git checkout -f mislav-fixes -q" should be run