提交 9126d28e 编写于 作者: I Ivan Tse

`fork` should fetch from the same "origin" Github URL.

上级 179ef88e
......@@ -17,6 +17,20 @@ Feature: hub fork
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"
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' }
get('/repos/mislav/dotfiles', :host_name => 'api.github.com') { 404 }
post('/repos/evilchelu/dotfiles/forks', :host_name => 'api.github.com') { '' }
"""
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"
Scenario: --no-remote
Given the GitHub API server:
"""
......
......@@ -556,8 +556,9 @@ module Hub
if args.include?('--no-remote')
exit
else
origin_url = project.remote.github_url
url = forked_project.git_url(:private => true, :https => https_protocol?)
args.replace %W"remote add -f #{forked_project.owner} #{project.git_url}"
args.replace %W"remote add -f #{forked_project.owner} #{origin_url}"
args.after %W"remote set-url #{forked_project.owner} #{url}"
args.after 'echo', ['new remote:', forked_project.owner]
end
......
......@@ -397,6 +397,10 @@ module Hub
nil
end
def github_url
urls.detect {|url| local_repo.known_host?(url.host) }
end
def urls
@urls ||= raw_urls.map do |url|
with_normalized_url(url) do |normalized|
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册