提交 e2563e1d 编写于 作者: J Jingwen Owen Ou

Merge branch 'tgkokk-gh-clone-fix'

......@@ -46,12 +46,17 @@ func transformCloneArgs(args *Args) {
continue
}
if github.MatchURL(a) != nil {
break
}
if nameWithOwnerRegexp.MatchString(a) && !isDir(a) {
name, owner := parseCloneNameAndOwner(a)
config := github.CurrentConfig()
isSSH = isSSH || owner == config.User
if owner == "" {
owner = config.User
isSSH = true
}
project := github.Project{Name: name, Owner: owner}
......
......@@ -42,11 +42,18 @@ func TestTransformCloneArgs(t *testing.T) {
transformCloneArgs(args)
assert.Equal(t, 1, args.ParamsSize())
assert.Equal(t, "git://github.com/jingweno/jekyll_and_hyde.git", args.FirstParam())
assert.Equal(t, "git@github.com:jingweno/jekyll_and_hyde.git", args.FirstParam())
args = NewArgs([]string{"clone", "-p", "jekyll_and_hyde"})
transformCloneArgs(args)
assert.Equal(t, 1, args.ParamsSize())
assert.Equal(t, "git@github.com:jingweno/jekyll_and_hyde.git", args.FirstParam())
args = NewArgs([]string{"clone", "git://github.com/jingweno/gh", "gh"})
transformCloneArgs(args)
assert.Equal(t, 2, args.ParamsSize())
assert.Equal(t, "git://github.com/jingweno/gh", args.FirstParam())
assert.Equal(t, "gh", args.GetParam(1))
}
......@@ -125,21 +125,30 @@ func parseOwnerAndName(remote string) (owner string, name string) {
return url[1], url[2]
}
func mustMatchGitHubURL(url string) ([]string, error) {
func MatchURL(url string) []string {
httpRegex := regexp.MustCompile("https://github\\.com/(.+)/(.+?)(\\.git|$)")
if httpRegex.MatchString(url) {
return httpRegex.FindStringSubmatch(url), nil
return httpRegex.FindStringSubmatch(url)
}
readOnlyRegex := regexp.MustCompile("git://github\\.com/(.+)/(.+?)(\\.git|$)")
if readOnlyRegex.MatchString(url) {
return readOnlyRegex.FindStringSubmatch(url), nil
return readOnlyRegex.FindStringSubmatch(url)
}
sshRegex := regexp.MustCompile("git@github\\.com:(.+)/(.+?)(\\.git|$)")
if sshRegex.MatchString(url) {
return sshRegex.FindStringSubmatch(url), nil
return sshRegex.FindStringSubmatch(url)
}
return nil
}
func mustMatchGitHubURL(url string) ([]string, error) {
githubURL := MatchURL(url)
if githubURL == nil {
return nil, errors.New("The origin remote doesn't point to a GitHub repository: " + url)
}
return nil, errors.New("The origin remote doesn't point to a GitHub repository: " + url)
return githubURL, nil
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册