fork.feature 5.8 KB
Newer Older
1 2 3 4 5 6 7 8 9
Feature: hub fork
  Background:
    Given I am in "dotfiles" git repo
    And the "origin" remote has url "git://github.com/evilchelu/dotfiles.git"
    And I am "mislav" on github.com with OAuth token "OTOKEN"

  Scenario: Fork the repository
    Given the GitHub API server:
      """
10 11 12 13
      before {
        halt 400 unless request.env['HTTP_X_ORIGINAL_SCHEME'] == 'https'
        halt 401 unless request.env['HTTP_AUTHORIZATION'] == 'token OTOKEN'
      }
J
Jingwen Owen Ou 已提交
14
      get('/repos/mislav/dotfiles', :host_name => 'api.github.com') { 404 }
15
      post('/repos/evilchelu/dotfiles/forks', :host_name => 'api.github.com') { '' }
16 17 18
      """
    When I successfully run `hub fork`
    Then the output should contain exactly "new remote: mislav\n"
19 20
    And "git remote add -f mislav git://github.com/evilchelu/dotfiles.git" should be run
    And "git remote set-url mislav git@github.com:mislav/dotfiles.git" should be run
21 22
    And the url for "mislav" should be "git@github.com:mislav/dotfiles.git"

23 24 25 26 27
  Scenario: Fork the repository when origin URL is private
    Given the "origin" remote has url "git@github.com:evilchelu/dotfiles.git"
    Given the GitHub API server:
      """
      before { halt 401 unless request.env['HTTP_AUTHORIZATION'] == 'token OTOKEN' }
28 29
      get('/repos/mislav/dotfiles', :host_name => 'api.github.com') { 404 }
      post('/repos/evilchelu/dotfiles/forks', :host_name => 'api.github.com') { '' }
30 31 32 33 34 35 36
      """
    When I successfully run `hub fork`
    Then the output should contain exactly "new remote: mislav\n"
    And "git remote add -f mislav ssh://git@github.com/evilchelu/dotfiles.git" should be run
    And "git remote set-url mislav git@github.com:mislav/dotfiles.git" should be run
    And the url for "mislav" should be "git@github.com:mislav/dotfiles.git"

37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
  Scenario: --no-remote
    Given the GitHub API server:
      """
      post('/repos/evilchelu/dotfiles/forks') { '' }
      """
    When I successfully run `hub fork --no-remote`
    Then there should be no output
    And there should be no "mislav" remote

  Scenario: Fork failed
    Given the GitHub API server:
      """
      post('/repos/evilchelu/dotfiles/forks') { halt 500 }
      """
    When I run `hub fork`
    Then the exit status should be 1
    And the stderr should contain exactly:
      """
      Error creating fork: Internal Server Error (HTTP 500)\n
      """
    And there should be no "mislav" remote

59
  Scenario: Unrelated fork already exists
60 61
    Given the GitHub API server:
      """
62
      get('/repos/mislav/dotfiles') {
63
        halt 406 unless request.env['HTTP_ACCEPT'] == 'application/vnd.github.v3+json;charset=utf-8'
64 65
        json :parent => { :html_url => 'https://github.com/unrelated/dotfiles' }
      }
66 67 68 69 70
      """
    When I run `hub fork`
    Then the exit status should be 1
    And the stderr should contain exactly:
      """
71
      Error creating fork: mislav/dotfiles already exists on github.com\n
72 73 74
      """
    And there should be no "mislav" remote

75 76 77
Scenario: Related fork already exists
    Given the GitHub API server:
      """
78 79 80
      get('/repos/mislav/dotfiles') {
        json :parent => { :html_url => 'https://github.com/evilchelu/dotfiles' }
      }
81 82 83 84 85
      """
    When I run `hub fork`
    Then the exit status should be 0
    And the url for "mislav" should be "git@github.com:mislav/dotfiles.git"

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: Invalid OAuth token
    Given the GitHub API server:
      """
      before { halt 401 unless request.env['HTTP_AUTHORIZATION'] == 'token OTOKEN' }
      """
    And I am "mislav" on github.com with OAuth token "WRONGTOKEN"
    When I run `hub fork`
    Then the exit status should be 1
    And the stderr should contain exactly:
      """
      Error creating fork: Unauthorized (HTTP 401)\n
      """

  Scenario: HTTPS is preferred
    Given the GitHub API server:
      """
      post('/repos/evilchelu/dotfiles/forks') { '' }
      """
    And HTTPS is preferred
    When I successfully run `hub fork`
    Then the output should contain exactly "new remote: mislav\n"
    And the url for "mislav" should be "https://github.com/mislav/dotfiles.git"

  Scenario: Not in repo
    Given the current dir is not a repo
    When I run `hub fork`
    Then the exit status should be 1
    And the stderr should contain "fatal: Not a git repository"

  Scenario: Unknown host
    Given the "origin" remote has url "git@git.my.org:evilchelu/dotfiles.git"
    When I run `hub fork`
    Then the exit status should be 1
    And the stderr should contain exactly:
      """
      Error: repository under 'origin' remote is not a GitHub project\n
      """

  Scenario: Enterprise fork
    Given the GitHub API server:
      """
127 128 129 130
      before {
        halt 400 unless request.env['HTTP_X_ORIGINAL_SCHEME'] == 'https'
        halt 401 unless request.env['HTTP_AUTHORIZATION'] == 'token FITOKEN'
      }
131
      post('/api/v3/repos/evilchelu/dotfiles/forks', :host_name => 'git.my.org') { '' }
132 133 134 135 136 137
      """
    And the "origin" remote has url "git@git.my.org:evilchelu/dotfiles.git"
    And I am "mislav" on git.my.org with OAuth token "FITOKEN"
    And "git.my.org" is a whitelisted Enterprise host
    When I successfully run `hub fork`
    Then the url for "mislav" should be "git@git.my.org:mislav/dotfiles.git"
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152

  Scenario: Enterprise fork using regular HTTP
    Given the GitHub API server:
      """
      before {
        halt 400 unless request.env['HTTP_X_ORIGINAL_SCHEME'] == 'http'
        halt 401 unless request.env['HTTP_AUTHORIZATION'] == 'token FITOKEN'
      }
      post('/api/v3/repos/evilchelu/dotfiles/forks', :host_name => 'git.my.org') { '' }
      """
    And the "origin" remote has url "git@git.my.org:evilchelu/dotfiles.git"
    And I am "mislav" on http://git.my.org with OAuth token "FITOKEN"
    And "git.my.org" is a whitelisted Enterprise host
    When I successfully run `hub fork`
    Then the url for "mislav" should be "git@git.my.org:mislav/dotfiles.git"