提交 d3ac6c47 编写于 作者: M Mislav Marohnić

Fix `hub create` in place of a renamed repo

If you're trying to create `owner/foo` repo and there is an existing
redirect from `owner/foo` to a differently name repo, don't consider
that one as an existing repo and proceed with creating `owner/foo`.
上级 d6a9a445
......@@ -110,15 +110,24 @@ func create(command *Command, args *Args) {
gh := github.NewClient(project.Host)
repo, err := gh.Repository(project)
if err == nil {
if !repo.Private && flagCreatePrivate {
err = fmt.Errorf("Repository '%s' already exists and is public", repo.FullName)
utils.Check(err)
foundProject := github.NewProject(repo.FullName, "", project.Host)
if foundProject.SameAs(project) {
if !repo.Private && flagCreatePrivate {
err = fmt.Errorf("Repository '%s' already exists and is public", repo.FullName)
utils.Check(err)
} else {
ui.Errorln("Existing repository detected. Updating git remote")
project = foundProject
}
} else {
ui.Errorln("Existing repository detected. Updating git remote")
repo = nil
}
} else {
repo = nil
}
if repo == nil {
if !args.Noop {
repo, err := gh.CreateRepository(project, flagCreateDescription, flagCreateHomepage, flagCreatePrivate)
utils.Check(err)
......
......@@ -358,7 +358,9 @@ Feature: OAuth authentication
get('/user') {
json :login => 'mislav'
}
get('/repos/mislav/dotfiles') { status 200 }
get('/repos/mislav/dotfiles') {
json :full_name => 'mislav/dotfiles'
}
"""
When I run `hub create` interactively
When I type "mislav@example.com"
......
......@@ -140,7 +140,9 @@ Feature: hub create
Scenario: GitHub repo already exists
Given the GitHub API server:
"""
get('/repos/mislav/dotfiles') { status 200 }
get('/repos/mislav/dotfiles') {
json :full_name => 'mislav/dotfiles'
}
"""
When I successfully run `hub create`
Then the output should contain "Existing repository detected. Updating git remote\n"
......@@ -170,6 +172,36 @@ Feature: hub create
When I successfully run `hub create -p`
Then the url for "origin" should be "git@github.com:mislav/dotfiles.git"
Scenario: Renamed GitHub repo already exists
Given the GitHub API server:
"""
get('/repos/mislav/dotfiles') {
redirect 'https://api.github.com/repositories/12345', 301
}
get('/repositories/12345') {
json :full_name => 'mislav/DOTfiles'
}
"""
When I successfully run `hub create`
And the url for "origin" should be "git@github.com:mislav/DOTfiles.git"
Scenario: Renamed GitHub repo is unrelated
Given the GitHub API server:
"""
get('/repos/mislav/dotfiles') {
redirect 'https://api.github.com/repositories/12345', 301
}
get('/repositories/12345') {
json :full_name => 'mislav/old-dotfiles'
}
post('/user/repos') {
status 201
json :full_name => 'mislav/mydotfiles'
}
"""
When I successfully run `hub create`
And the url for "origin" should be "git@github.com:mislav/mydotfiles.git"
Scenario: API response changes the clone URL
Given the GitHub API server:
"""
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册