提交 35f9c0ee 编写于 作者: G Giuseppe

Make fork --remote-name=origin rename origin

If user passes `origin` as the remote name
pointing to forked repository, it's likely
she wants to rename origin as upstream.
上级 2e882612
...@@ -112,7 +112,7 @@ func fork(cmd *Command, args *Args) { ...@@ -112,7 +112,7 @@ func fork(cmd *Command, args *Args) {
originURL := originRemote.URL.String() originURL := originRemote.URL.String()
url := forkProject.GitURL("", "", true) url := forkProject.GitURL("", "", true)
// Check to see if the remote already exists and points to the fork. // Check to see if the remote already exists.
currentRemote, err := localRepo.RemoteByName(newRemoteName) currentRemote, err := localRepo.RemoteByName(newRemoteName)
if err == nil { if err == nil {
currentProject, err := currentRemote.Project() currentProject, err := currentRemote.Project()
...@@ -121,6 +121,11 @@ func fork(cmd *Command, args *Args) { ...@@ -121,6 +121,11 @@ func fork(cmd *Command, args *Args) {
ui.Printf("existing remote: %s\n", newRemoteName) ui.Printf("existing remote: %s\n", newRemoteName)
return return
} }
if newRemoteName == "origin" {
// Assume user wants to follow github guides for collaboration
ui.Printf("renaming existing \"origin\" remote to \"upstream\"\n")
args.Before("git", "remote", "rename", "origin", "upstream")
}
} }
} }
......
...@@ -34,12 +34,16 @@ Feature: hub fork ...@@ -34,12 +34,16 @@ Feature: hub fork
json :name => 'dotfiles', :owner => { :login => 'mislav' } json :name => 'dotfiles', :owner => { :login => 'mislav' }
} }
""" """
And I successfully run `git remote rename origin upstream`
When I successfully run `hub fork --remote-name=origin` When I successfully run `hub fork --remote-name=origin`
Then the output should contain exactly "new remote: origin\n" Then the output should contain exactly:
"""
renaming existing "origin" remote to "upstream"
new remote: origin\n
"""
And "git remote add -f origin git://github.com/evilchelu/dotfiles.git" should be run And "git remote add -f origin git://github.com/evilchelu/dotfiles.git" should be run
And "git remote set-url origin git@github.com:mislav/dotfiles.git" should be run And "git remote set-url origin git@github.com:mislav/dotfiles.git" should be run
And the url for "origin" should be "git@github.com:mislav/dotfiles.git" And the url for "origin" should be "git@github.com:mislav/dotfiles.git"
And the url for "upstream" should be "git://github.com/evilchelu/dotfiles.git"
Scenario: Fork the repository with redirect Scenario: Fork the repository with redirect
Given the GitHub API server: Given the GitHub API server:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册