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

Support `remote add -t BRANCH` argument

上级 2c14e781
......@@ -89,18 +89,20 @@ func transformRemoteArgs(args *Args) {
}
host = hostConfig.Host
words := args.Words()
isPrivate := parseRemotePrivateFlag(args)
if len(words) == 2 && words[1] == "origin" {
// Origin special case triggers default user/repo
owner = hostConfig.User
} else if len(words) == 2 {
// gh remote add jingweno foo/bar
if idx := args.IndexOfParam(words[1]); idx != -1 {
args.ReplaceParam(idx, owner)
numWord := 0
for i, p := range args.Params {
if !looksLikeFlag(p) && (i < 1 || args.Params[i-1] != "-t") {
numWord += 1
if numWord == 2 && strings.Contains(p, "/") {
args.ReplaceParam(i, owner)
} else if numWord == 3 {
args.RemoveParam(i)
}
}
} else {
args.RemoveParam(args.ParamsSize() - 1)
}
if numWord == 2 && owner == "origin" {
owner = hostConfig.User
}
if strings.ToLower(owner) == strings.ToLower(hostConfig.User) {
......@@ -109,9 +111,7 @@ func transformRemoteArgs(args *Args) {
}
project := github.NewProject(owner, name, host)
// for GitHub Enterprise
isPrivate = isPrivate || project.Host != github.GitHubHost
url := project.GitURL(name, owner, isPrivate)
url := project.GitURL("", "", isPrivate || project.Host != github.GitHubHost)
args.AppendParams(url)
}
......@@ -125,20 +125,11 @@ func parseRemotePrivateFlag(args *Args) bool {
}
func parseRepoNameOwner(nameWithOwner string) (owner, name string) {
ownerRe := fmt.Sprintf("^(%s)$", OwnerRe)
ownerRegexp := regexp.MustCompile(ownerRe)
if ownerRegexp.MatchString(nameWithOwner) {
owner = ownerRegexp.FindStringSubmatch(nameWithOwner)[1]
return
}
nameWithOwnerRe := fmt.Sprintf("^(%s)\\/(%s)$", OwnerRe, NameRe)
nameWithOwnerRe := fmt.Sprintf("^(%s)(?:\\/(%s))?$", OwnerRe, NameRe)
nameWithOwnerRegexp := regexp.MustCompile(nameWithOwnerRe)
if nameWithOwnerRegexp.MatchString(nameWithOwner) {
result := nameWithOwnerRegexp.FindStringSubmatch(nameWithOwner)
owner = result[1]
name = result[2]
owner, name = result[1], result[2]
}
return
}
......@@ -70,6 +70,11 @@ Feature: hub remote add
Then "git remote add -f mislav git://github.com/mislav/dotfiles.git" should be run
And there should be no output
Scenario: Add remote with branch argument
When I successfully run `hub remote add -f -t feature mislav`
Then "git remote add -f -t feature mislav git://github.com/mislav/dotfiles.git" should be run
And there should be no output
Scenario: Add HTTPS protocol remote
Given HTTPS is preferred
When I successfully run `hub remote add mislav`
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册