Merge branch 'tgkokk-dot-git-optional'

This commit is contained in:
Jingwen Owen Ou 2013-06-12 16:01:54 -07:00
Родитель d71250a62b 71d0534dbd
Коммит 851c45568d
2 изменённых файлов: 24 добавлений и 3 удалений

Просмотреть файл

@ -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])
}