зеркало из https://github.com/mislav/hub.git
Allow repository names that start with a dash character
These are allowed on GitHub.
This commit is contained in:
Родитель
e820f9da15
Коммит
dadc26d2e4
|
@ -9,9 +9,9 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
NameRe = "[\\w.][\\w.-]*"
|
||||
NameRe = `[\w.-]+`
|
||||
OwnerRe = "[a-zA-Z0-9][a-zA-Z0-9-]*"
|
||||
NameWithOwnerRe = fmt.Sprintf("^(?:%s|%s\\/%s)$", NameRe, OwnerRe, NameRe)
|
||||
NameWithOwnerRe = fmt.Sprintf(`^(%s/)?%s$`, OwnerRe, NameRe)
|
||||
|
||||
CmdRunner = NewRunner()
|
||||
)
|
||||
|
|
|
@ -3,6 +3,7 @@ package commands
|
|||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"regexp"
|
||||
"testing"
|
||||
|
||||
"github.com/bmizerany/assert"
|
||||
|
@ -123,3 +124,23 @@ func TestSubCommandCall(t *testing.T) {
|
|||
c.Call(args)
|
||||
assert.Equal(t, "baz", result)
|
||||
}
|
||||
|
||||
func Test_NameWithOwnerRe(t *testing.T) {
|
||||
re := regexp.MustCompile(NameWithOwnerRe)
|
||||
|
||||
assert.Equal(t, true, re.MatchString("o/n"))
|
||||
assert.Equal(t, true, re.MatchString("own-er/my-project.git"))
|
||||
assert.Equal(t, true, re.MatchString("my-project.git"))
|
||||
assert.Equal(t, true, re.MatchString("my_project"))
|
||||
assert.Equal(t, true, re.MatchString("-dash"))
|
||||
assert.Equal(t, true, re.MatchString(".dotfiles"))
|
||||
|
||||
assert.Equal(t, false, re.MatchString(""))
|
||||
assert.Equal(t, false, re.MatchString("/"))
|
||||
assert.Equal(t, false, re.MatchString(" "))
|
||||
assert.Equal(t, false, re.MatchString("owner/na me"))
|
||||
assert.Equal(t, false, re.MatchString("owner/na/me"))
|
||||
assert.Equal(t, false, re.MatchString("own.er/name"))
|
||||
assert.Equal(t, false, re.MatchString("own_er/name"))
|
||||
assert.Equal(t, false, re.MatchString("-owner/name"))
|
||||
}
|
||||
|
|
|
@ -56,10 +56,17 @@ func remote(command *Command, args *Args) {
|
|||
|
||||
func transformRemoteArgs(args *Args) {
|
||||
ownerWithName := args.LastParam()
|
||||
owner, name := parseRepoNameOwner(ownerWithName)
|
||||
if owner == "" {
|
||||
|
||||
re := regexp.MustCompile(fmt.Sprintf(`^%s(/%s)?$`, OwnerRe, NameRe))
|
||||
if !re.MatchString(ownerWithName) {
|
||||
return
|
||||
}
|
||||
owner := ownerWithName
|
||||
name := ""
|
||||
if strings.Contains(ownerWithName, "/") {
|
||||
parts := strings.SplitN(ownerWithName, "/", 2)
|
||||
owner, name = parts[0], parts[1]
|
||||
}
|
||||
|
||||
localRepo, err := github.LocalRepo()
|
||||
utils.Check(err)
|
||||
|
@ -141,13 +148,3 @@ func parseRemotePrivateFlag(args *Args) bool {
|
|||
|
||||
return false
|
||||
}
|
||||
|
||||
func parseRepoNameOwner(nameWithOwner string) (owner, name string) {
|
||||
nameWithOwnerRe := fmt.Sprintf("^(%s)(?:\\/(%s))?$", OwnerRe, NameRe)
|
||||
nameWithOwnerRegexp := regexp.MustCompile(nameWithOwnerRe)
|
||||
if nameWithOwnerRegexp.MatchString(nameWithOwner) {
|
||||
result := nameWithOwnerRegexp.FindStringSubmatch(nameWithOwner)
|
||||
owner, name = result[1], result[2]
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
|
@ -10,16 +10,6 @@ import (
|
|||
"github.com/github/hub/github"
|
||||
)
|
||||
|
||||
func TestParseRepoNameOwner(t *testing.T) {
|
||||
owner, repo := parseRepoNameOwner("jingweno")
|
||||
assert.Equal(t, "jingweno", owner)
|
||||
assert.Equal(t, "", repo)
|
||||
|
||||
owner, repo = parseRepoNameOwner("jingweno/gh")
|
||||
assert.Equal(t, "jingweno", owner)
|
||||
assert.Equal(t, "gh", repo)
|
||||
}
|
||||
|
||||
func TestTransformRemoteArgs(t *testing.T) {
|
||||
repo := fixtures.SetupTestRepo()
|
||||
defer repo.TearDown()
|
||||
|
|
Загрузка…
Ссылка в новой задаче