Browse code

Allow git@ prefixes for any hosted git service

Signed-off-by: Aidan Hobson Sayers <aidanhs@cantab.net>

Aidan Hobson Sayers authored on 2014/11/14 10:52:55
Showing 3 changed files
... ...
@@ -462,7 +462,7 @@ Supported formats are: bzip2, gzip and xz.
462 462
 This will clone the GitHub repository and use the cloned repository as
463 463
 context. The Dockerfile at the root of the
464 464
 repository is used as Dockerfile. Note that you
465
-can specify an arbitrary Git repository by using the `git://`
465
+can specify an arbitrary Git repository by using the `git://` or `git@`
466 466
 schema.
467 467
 
468 468
 > **Note:** `docker build` will return a `no such file or directory` error
... ...
@@ -293,7 +293,7 @@ func IsURL(str string) bool {
293 293
 }
294 294
 
295 295
 func IsGIT(str string) bool {
296
-	return strings.HasPrefix(str, "git://") || strings.HasPrefix(str, "github.com/") || strings.HasPrefix(str, "git@github.com:") || (strings.HasSuffix(str, ".git") && IsURL(str))
296
+	return strings.HasPrefix(str, "git://") || strings.HasPrefix(str, "github.com/") || strings.HasPrefix(str, "git@") || (strings.HasSuffix(str, ".git") && IsURL(str))
297 297
 }
298 298
 
299 299
 func ValidGitTransport(str string) bool {
... ...
@@ -98,23 +98,42 @@ func TestReadSymlinkedDirectoryToFile(t *testing.T) {
98 98
 	}
99 99
 }
100 100
 
101
-func TestValidGitTransport(t *testing.T) {
102
-	for _, url := range []string{
101
+var (
102
+	gitUrls = []string{
103 103
 		"git://github.com/docker/docker",
104 104
 		"git@github.com:docker/docker.git",
105
+		"git@bitbucket.org:atlassianlabs/atlassian-docker.git",
105 106
 		"https://github.com/docker/docker.git",
106 107
 		"http://github.com/docker/docker.git",
107
-	} {
108
+	}
109
+	incompleteGitUrls = []string{
110
+		"github.com/docker/docker",
111
+	}
112
+)
113
+
114
+func TestValidGitTransport(t *testing.T) {
115
+	for _, url := range gitUrls {
108 116
 		if ValidGitTransport(url) == false {
109 117
 			t.Fatalf("%q should be detected as valid Git prefix", url)
110 118
 		}
111 119
 	}
112 120
 
113
-	for _, url := range []string{
114
-		"github.com/docker/docker",
115
-	} {
121
+	for _, url := range incompleteGitUrls {
116 122
 		if ValidGitTransport(url) == true {
117 123
 			t.Fatalf("%q should not be detected as valid Git prefix", url)
118 124
 		}
119 125
 	}
120 126
 }
127
+
128
+func TestIsGIT(t *testing.T) {
129
+	for _, url := range gitUrls {
130
+		if IsGIT(url) == false {
131
+			t.Fatalf("%q should be detected as valid Git url", url)
132
+		}
133
+	}
134
+	for _, url := range incompleteGitUrls {
135
+		if IsGIT(url) == false {
136
+			t.Fatalf("%q should be detected as valid Git url", url)
137
+		}
138
+	}
139
+}