Use git url fragment to specify reference and dir context.
Signed-off-by: David Calavera <david.calavera@gmail.com>
This commit is contained in:
parent
1ad5a79e51
commit
99c755ad1d
2 changed files with 19 additions and 2 deletions
|
@ -1,6 +1,9 @@
|
|||
package urlutil
|
||||
|
||||
import "strings"
|
||||
import (
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var (
|
||||
validPrefixes = []string{
|
||||
|
@ -8,11 +11,13 @@ var (
|
|||
"github.com/",
|
||||
"git@",
|
||||
}
|
||||
|
||||
urlPathWithFragmentSuffix = regexp.MustCompile(".git(?:#.+)?$")
|
||||
)
|
||||
|
||||
// IsGitURL returns true if the provided str is a git repository URL.
|
||||
func IsGitURL(str string) bool {
|
||||
if IsURL(str) && strings.HasSuffix(str, ".git") {
|
||||
if IsURL(str) && urlPathWithFragmentSuffix.MatchString(str) {
|
||||
return true
|
||||
}
|
||||
for _, prefix := range validPrefixes {
|
||||
|
|
|
@ -9,10 +9,15 @@ var (
|
|||
"git@bitbucket.org:atlassianlabs/atlassian-docker.git",
|
||||
"https://github.com/docker/docker.git",
|
||||
"http://github.com/docker/docker.git",
|
||||
"http://github.com/docker/docker.git#branch",
|
||||
"http://github.com/docker/docker.git#:dir",
|
||||
}
|
||||
incompleteGitUrls = []string{
|
||||
"github.com/docker/docker",
|
||||
}
|
||||
invalidGitUrls = []string{
|
||||
"http://github.com/docker/docker.git:#branch",
|
||||
}
|
||||
)
|
||||
|
||||
func TestValidGitTransport(t *testing.T) {
|
||||
|
@ -35,9 +40,16 @@ func TestIsGIT(t *testing.T) {
|
|||
t.Fatalf("%q should be detected as valid Git url", url)
|
||||
}
|
||||
}
|
||||
|
||||
for _, url := range incompleteGitUrls {
|
||||
if IsGitURL(url) == false {
|
||||
t.Fatalf("%q should be detected as valid Git url", url)
|
||||
}
|
||||
}
|
||||
|
||||
for _, url := range invalidGitUrls {
|
||||
if IsGitURL(url) == true {
|
||||
t.Fatalf("%q should not be detected as valid Git prefix", url)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue