Add HasValidGITPrefix to utils/utils.go

This will allow us to use a common Git prefix check for both api/clients/commands.go and
builder/job.go. Previous prefix check in build from Git (in builder/jobs.go) ignored valid prefixes such as "git@", "http://" or "https://".

Signed-off-by: Lakshan Perera <lakshan@laktek.com>
This commit is contained in:
Lakshan Perera
2014-10-26 03:25:25 +00:00
parent 6ce4f82ebe
commit d3ac9ea98e
4 changed files with 27 additions and 3 deletions
+4
View File
@@ -304,6 +304,10 @@ func IsGIT(str string) bool {
return strings.HasPrefix(str, "git://") || strings.HasPrefix(str, "github.com/") || strings.HasPrefix(str, "git@github.com:") || (strings.HasSuffix(str, ".git") && IsURL(str))
}
func ValidGitTransport(str string) bool {
return strings.HasPrefix(str, "git://") || strings.HasPrefix(str, "git@") || IsURL(str)
}
var (
localHostRx = regexp.MustCompile(`(?m)^nameserver 127[^\n]+\n*`)
)
+21
View File
@@ -97,3 +97,24 @@ func TestReadSymlinkedDirectoryToFile(t *testing.T) {
t.Errorf("failed to remove symlink: %s", err)
}
}
func TestValidGitTransport(t *testing.T) {
for _, url := range []string{
"git://github.com/docker/docker",
"git@github.com:docker/docker.git",
"https://github.com/docker/docker.git",
"http://github.com/docker/docker.git",
} {
if ValidGitTransport(url) == false {
t.Fatalf("%q should be detected as valid Git prefix", url)
}
}
for _, url := range []string{
"github.com/docker/docker",
} {
if ValidGitTransport(url) == true {
t.Fatalf("%q should not be detected as valid Git prefix", url)
}
}
}