Skip to content

Commit

Permalink
Use the repo name in the response for fetch url.
Browse files Browse the repository at this point in the history
The repository name of the pull request head doesn't necessarily match
the name of the project's repository. This can happen when a user forks
a project but already has a repository of the same name. Use the name
returned in the api response for the fetch url to avoid this edge case.
  • Loading branch information
Ivan Tse committed Mar 8, 2014
1 parent 212228a commit e723fd3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
21 changes: 18 additions & 3 deletions features/merge.feature
Expand Up @@ -11,7 +11,7 @@ Feature: hub merge
get('/repos/defunkt/hub/pulls/164') { json \
:head => {
:label => 'jfirebaugh:hub_merge',
:repo => {:private => false}
:repo => {:private => false, :name=>"hub"}
},
:title => "Add `hub merge` command"
}
Expand All @@ -34,7 +34,7 @@ Feature: hub merge
get('/repos/defunkt/hub/pulls/164') { json \
:head => {
:label => 'jfirebaugh:hub_merge',
:repo => {:private => false}
:repo => {:private => false, :name=>"hub"}
},
:title => "Add `hub merge` command"
}
Expand All @@ -55,7 +55,7 @@ Feature: hub merge
get('/repos/defunkt/hub/pulls/164') { json \
:head => {
:label => 'jfirebaugh:hub_merge',
:repo => {:private => true}
:repo => {:private => true, :name=>"hub"}
},
:title => "Add `hub merge` command"
}
Expand All @@ -82,6 +82,21 @@ Feature: hub merge
Error: jfirebaugh's fork is not available anymore\n
"""

Scenario: Renamed repo
Given the GitHub API server:
"""
require 'json'
get('/repos/defunkt/hub/pulls/164') { json \
:head => {
:label => 'jfirebaugh:hub_merge',
:repo => {:private => false, :name=>"hub-1"}
}
}
"""
And there is a commit named "jfirebaugh/hub_merge"
When I successfully run `hub merge https://github.com/defunkt/hub/pull/164`
Then "git fetch git://github.com/jfirebaugh/hub-1.git +refs/heads/hub_merge:refs/remotes/jfirebaugh/hub_merge" should be run

Scenario: Unchanged merge
When I run `hub merge master`
Then "git merge master" should be run
5 changes: 3 additions & 2 deletions lib/hub/commands.rb
Expand Up @@ -443,8 +443,9 @@ def merge(args)
user, branch = pull_data['head']['label'].split(':', 2)
abort "Error: #{user}'s fork is not available anymore" unless pull_data['head']['repo']

url = github_project(url.project_name, user).git_url(:private => pull_data['head']['repo']['private'],
:https => https_protocol?)
repo_name = pull_data['head']['repo']['name']
url = github_project(repo_name, user).git_url(:private => pull_data['head']['repo']['private'],
:https => https_protocol?)

merge_head = "#{user}/#{branch}"
args.before ['fetch', url, "+refs/heads/#{branch}:refs/remotes/#{merge_head}"]
Expand Down

0 comments on commit e723fd3

Please sign in to comment.