未验证 提交 ecc4df44 编写于 作者: M Mislav Marohnić 提交者: GitHub

Merge pull request #1855 from nrmitchi/publicprivateoopsies

Prevent setting a public upstream when creating a private repo.
......@@ -109,8 +109,15 @@ func create(command *Command, args *Args) {
project := github.NewProject(owner, newRepoName, host.Host)
gh := github.NewClient(project.Host)
if gh.IsRepositoryExist(project) {
ui.Errorln("Existing repository detected. Updating git remote")
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)
} else {
ui.Errorln("Existing repository detected. Updating git remote")
}
} else {
if !args.Noop {
repo, err := gh.CreateRepository(project, flagCreateDescription, flagCreateHomepage, flagCreatePrivate)
......
......@@ -146,6 +146,30 @@ Feature: hub create
Then the output should contain "Existing repository detected. Updating git remote\n"
And the url for "origin" should be "git@github.com:mislav/dotfiles.git"
Scenario: GitHub repo already exists and is not private
Given the GitHub API server:
"""
get('/repos/mislav/dotfiles') {
json :full_name => 'mislav/dotfiles',
:private => false
}
"""
When I run `hub create -p`
Then the output should contain "Repository 'mislav/dotfiles' already exists and is public\n"
And the exit status should be 1
And there should be no "origin" remote
Scenario: GitHub repo already exists and is private
Given the GitHub API server:
"""
get('/repos/mislav/dotfiles') {
json :full_name => 'mislav/dotfiles',
:private => true
}
"""
When I successfully run `hub create -p`
Then the url for "origin" should be "git@github.com:mislav/dotfiles.git"
Scenario: API response changes the clone URL
Given the GitHub API server:
"""
......
......@@ -213,12 +213,6 @@ func (client *Client) Repository(project *Project) (repo *Repository, err error)
return
}
func (client *Client) IsRepositoryExist(project *Project) bool {
repo, err := client.Repository(project)
return err == nil && repo != nil
}
func (client *Client) CreateRepository(project *Project, description, homepage string, isPrivate bool) (repo *Repository, err error) {
repoURL := "user/repos"
if project.Owner != client.Host.User {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册