зеркало из https://github.com/mislav/hub.git
Merge branch 'tgkokk-dot-git-optional'
This commit is contained in:
Коммит
851c45568d
|
@ -61,17 +61,17 @@ func parseOwnerAndName(remote string) (owner string, name string) {
|
|||
}
|
||||
|
||||
func mustMatchGitHubURL(url string) ([]string, error) {
|
||||
httpRegex := regexp.MustCompile("https://github.com/(.+)/(.+).git")
|
||||
httpRegex := regexp.MustCompile("https://github.com/(.+)/(.+?)(.git|$)")
|
||||
if httpRegex.MatchString(url) {
|
||||
return httpRegex.FindStringSubmatch(url), nil
|
||||
}
|
||||
|
||||
readOnlyRegex := regexp.MustCompile("git://github.com/(.+)/(.+).git")
|
||||
readOnlyRegex := regexp.MustCompile("git://github.com/(.+)/(.+?)(.git|$)")
|
||||
if readOnlyRegex.MatchString(url) {
|
||||
return readOnlyRegex.FindStringSubmatch(url), nil
|
||||
}
|
||||
|
||||
sshRegex := regexp.MustCompile("git@github.com:(.+)/(.+).git")
|
||||
sshRegex := regexp.MustCompile("git@github.com:(.+)/(.+?)(.git|$)")
|
||||
if sshRegex.MatchString(url) {
|
||||
return sshRegex.FindStringSubmatch(url), nil
|
||||
}
|
||||
|
|
|
@ -23,10 +23,31 @@ func TestParseOwnerAndName(t *testing.T) {
|
|||
func TestMustMatchGitHubURL(t *testing.T) {
|
||||
url, _ := mustMatchGitHubURL("git://github.com/jingweno/gh.git")
|
||||
assert.Equal(t, "git://github.com/jingweno/gh.git", url[0])
|
||||
assert.Equal(t, "jingweno", url[1])
|
||||
assert.Equal(t, "gh", url[2])
|
||||
|
||||
url, _ = mustMatchGitHubURL("git://github.com/jingweno/gh")
|
||||
assert.Equal(t, "git://github.com/jingweno/gh", url[0])
|
||||
assert.Equal(t, "jingweno", url[1])
|
||||
assert.Equal(t, "gh", url[2])
|
||||
|
||||
url, _ = mustMatchGitHubURL("git@github.com:jingweno/gh.git")
|
||||
assert.Equal(t, "git@github.com:jingweno/gh.git", url[0])
|
||||
assert.Equal(t, "jingweno", url[1])
|
||||
assert.Equal(t, "gh", url[2])
|
||||
|
||||
url, _ = mustMatchGitHubURL("git@github.com:jingweno/gh")
|
||||
assert.Equal(t, "git@github.com:jingweno/gh", url[0])
|
||||
assert.Equal(t, "jingweno", url[1])
|
||||
assert.Equal(t, "gh", url[2])
|
||||
|
||||
url, _ = mustMatchGitHubURL("https://github.com/jingweno/gh.git")
|
||||
assert.Equal(t, "https://github.com/jingweno/gh.git", url[0])
|
||||
assert.Equal(t, "jingweno", url[1])
|
||||
assert.Equal(t, "gh", url[2])
|
||||
|
||||
url, _ = mustMatchGitHubURL("https://github.com/jingweno/gh")
|
||||
assert.Equal(t, "https://github.com/jingweno/gh", url[0])
|
||||
assert.Equal(t, "jingweno", url[1])
|
||||
assert.Equal(t, "gh", url[2])
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче