github.com/scorpionis/hub@v2.2.1+incompatible/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 {
    11          halt 400 unless request.env['HTTP_X_ORIGINAL_SCHEME'] == 'https'
    12          halt 401 unless request.env['HTTP_AUTHORIZATION'] == 'token OTOKEN'
    13        }
    14        get('/repos/mislav/dotfiles', :host_name => 'api.github.com') { 404 }
    15        post('/repos/evilchelu/dotfiles/forks', :host_name => 'api.github.com') { '' }
    16        """
    17      When I successfully run `hub fork`
    18      Then the output should contain exactly "new remote: mislav\n"
    19      And "git remote add -f mislav git://github.com/evilchelu/dotfiles.git" should be run
    20      And "git remote set-url mislav git@github.com:mislav/dotfiles.git" should be run
    21      And the url for "mislav" should be "git@github.com:mislav/dotfiles.git"
    22  
    23    Scenario: Fork the repository when origin URL is private
    24      Given the "origin" remote has url "git@github.com:evilchelu/dotfiles.git"
    25      Given the GitHub API server:
    26        """
    27        before { halt 401 unless request.env['HTTP_AUTHORIZATION'] == 'token OTOKEN' }
    28        get('/repos/mislav/dotfiles', :host_name => 'api.github.com') { 404 }
    29        post('/repos/evilchelu/dotfiles/forks', :host_name => 'api.github.com') { '' }
    30        """
    31      When I successfully run `hub fork`
    32      Then the output should contain exactly "new remote: mislav\n"
    33      And "git remote add -f mislav ssh://git@github.com/evilchelu/dotfiles.git" should be run
    34      And "git remote set-url mislav git@github.com:mislav/dotfiles.git" should be run
    35      And the url for "mislav" should be "git@github.com:mislav/dotfiles.git"
    36  
    37    Scenario: --no-remote
    38      Given the GitHub API server:
    39        """
    40        post('/repos/evilchelu/dotfiles/forks') { '' }
    41        """
    42      When I successfully run `hub fork --no-remote`
    43      Then there should be no output
    44      And there should be no "mislav" remote
    45  
    46    Scenario: Fork failed
    47      Given the GitHub API server:
    48        """
    49        post('/repos/evilchelu/dotfiles/forks') { halt 500 }
    50        """
    51      When I run `hub fork`
    52      Then the exit status should be 1
    53      And the stderr should contain exactly:
    54        """
    55        Error creating fork: Internal Server Error (HTTP 500)\n
    56        """
    57      And there should be no "mislav" remote
    58  
    59    Scenario: Unrelated fork already exists
    60      Given the GitHub API server:
    61        """
    62        get('/repos/mislav/dotfiles') {
    63          halt 406 unless request.env['HTTP_ACCEPT'] == 'application/vnd.github.v3+json;charset=utf-8'
    64          json :parent => { :html_url => 'https://github.com/unrelated/dotfiles' }
    65        }
    66        """
    67      When I run `hub fork`
    68      Then the exit status should be 1
    69      And the stderr should contain exactly:
    70        """
    71        Error creating fork: mislav/dotfiles already exists on github.com\n
    72        """
    73      And there should be no "mislav" remote
    74  
    75  Scenario: Related fork already exists
    76      Given the GitHub API server:
    77        """
    78        get('/repos/mislav/dotfiles') {
    79          json :parent => { :html_url => 'https://github.com/evilchelu/dotfiles' }
    80        }
    81        """
    82      When I run `hub fork`
    83      Then the exit status should be 0
    84      And the url for "mislav" should be "git@github.com:mislav/dotfiles.git"
    85  
    86    Scenario: Invalid OAuth token
    87      Given the GitHub API server:
    88        """
    89        before { halt 401 unless request.env['HTTP_AUTHORIZATION'] == 'token OTOKEN' }
    90        """
    91      And I am "mislav" on github.com with OAuth token "WRONGTOKEN"
    92      When I run `hub fork`
    93      Then the exit status should be 1
    94      And the stderr should contain exactly:
    95        """
    96        Error creating fork: Unauthorized (HTTP 401)\n
    97        """
    98  
    99    Scenario: HTTPS is preferred
   100      Given the GitHub API server:
   101        """
   102        post('/repos/evilchelu/dotfiles/forks') { '' }
   103        """
   104      And HTTPS is preferred
   105      When I successfully run `hub fork`
   106      Then the output should contain exactly "new remote: mislav\n"
   107      And the url for "mislav" should be "https://github.com/mislav/dotfiles.git"
   108  
   109    Scenario: Not in repo
   110      Given the current dir is not a repo
   111      When I run `hub fork`
   112      Then the exit status should be 1
   113      And the stderr should contain "fatal: Not a git repository"
   114  
   115    Scenario: Unknown host
   116      Given the "origin" remote has url "git@git.my.org:evilchelu/dotfiles.git"
   117      When I run `hub fork`
   118      Then the exit status should be 1
   119      And the stderr should contain exactly:
   120        """
   121        Error: repository under 'origin' remote is not a GitHub project\n
   122        """
   123  
   124    Scenario: Enterprise fork
   125      Given the GitHub API server:
   126        """
   127        before {
   128          halt 400 unless request.env['HTTP_X_ORIGINAL_SCHEME'] == 'https'
   129          halt 401 unless request.env['HTTP_AUTHORIZATION'] == 'token FITOKEN'
   130        }
   131        post('/api/v3/repos/evilchelu/dotfiles/forks', :host_name => 'git.my.org') { '' }
   132        """
   133      And the "origin" remote has url "git@git.my.org:evilchelu/dotfiles.git"
   134      And I am "mislav" on git.my.org with OAuth token "FITOKEN"
   135      And "git.my.org" is a whitelisted Enterprise host
   136      When I successfully run `hub fork`
   137      Then the url for "mislav" should be "git@git.my.org:mislav/dotfiles.git"
   138  
   139    Scenario: Enterprise fork using regular HTTP
   140      Given the GitHub API server:
   141        """
   142        before {
   143          halt 400 unless request.env['HTTP_X_ORIGINAL_SCHEME'] == 'http'
   144          halt 400 unless request.env['HTTP_X_ORIGINAL_PORT'] == '80'
   145          halt 401 unless request.env['HTTP_AUTHORIZATION'] == 'token FITOKEN'
   146        }
   147        post('/api/v3/repos/evilchelu/dotfiles/forks', :host_name => 'git.my.org') { '' }
   148        """
   149      And the "origin" remote has url "git@git.my.org:evilchelu/dotfiles.git"
   150      And I am "mislav" on http://git.my.org with OAuth token "FITOKEN"
   151      And "git.my.org" is a whitelisted Enterprise host
   152      When I successfully run `hub fork`
   153      Then the url for "mislav" should be "git@git.my.org:mislav/dotfiles.git"