Browse code

Move IsGitTransport() to gitutils

This function was only used inside gitutils,
and is written specifically for the requirements
there.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Sebastiaan van Stijn authored on 2017/06/27 02:07:04
Showing 4 changed files
... ...
@@ -57,7 +57,7 @@ func Clone(remoteURL string) (string, error) {
57 57
 func parseRemoteURL(remoteURL string) (gitRepo, error) {
58 58
 	repo := gitRepo{}
59 59
 
60
-	if !urlutil.IsGitTransport(remoteURL) {
60
+	if !isGitTransport(remoteURL) {
61 61
 		remoteURL = "https://" + remoteURL
62 62
 	}
63 63
 
... ...
@@ -151,3 +151,9 @@ func gitWithinDir(dir string, args ...string) ([]byte, error) {
151 151
 func git(args ...string) ([]byte, error) {
152 152
 	return exec.Command("git", args...).CombinedOutput()
153 153
 }
154
+
155
+// isGitTransport returns true if the provided str is a git transport by inspecting
156
+// the prefix of the string for known protocols used in git.
157
+func isGitTransport(str string) bool {
158
+	return urlutil.IsURL(str) || strings.HasPrefix(str, "git://") || strings.HasPrefix(str, "git@")
159
+}
... ...
@@ -209,3 +209,30 @@ func TestCheckoutGit(t *testing.T) {
209 209
 		assert.Equal(t, c.exp, string(b))
210 210
 	}
211 211
 }
212
+
213
+func TestValidGitTransport(t *testing.T) {
214
+	gitUrls := []string{
215
+		"git://github.com/docker/docker",
216
+		"git@github.com:docker/docker.git",
217
+		"git@bitbucket.org:atlassianlabs/atlassian-docker.git",
218
+		"https://github.com/docker/docker.git",
219
+		"http://github.com/docker/docker.git",
220
+		"http://github.com/docker/docker.git#branch",
221
+		"http://github.com/docker/docker.git#:dir",
222
+	}
223
+	incompleteGitUrls := []string{
224
+		"github.com/docker/docker",
225
+	}
226
+
227
+	for _, url := range gitUrls {
228
+		if !isGitTransport(url) {
229
+			t.Fatalf("%q should be detected as valid Git prefix", url)
230
+		}
231
+	}
232
+
233
+	for _, url := range incompleteGitUrls {
234
+		if isGitTransport(url) {
235
+			t.Fatalf("%q should not be detected as valid Git prefix", url)
236
+		}
237
+	}
238
+}
... ...
@@ -29,12 +29,6 @@ func IsGitURL(str string) bool {
29 29
 	return checkURL(str, "git")
30 30
 }
31 31
 
32
-// IsGitTransport returns true if the provided str is a git transport by inspecting
33
-// the prefix of the string for known protocols used in git.
34
-func IsGitTransport(str string) bool {
35
-	return IsURL(str) || strings.HasPrefix(str, "git://") || strings.HasPrefix(str, "git@")
36
-}
37
-
38 32
 // IsTransportURL returns true if the provided str is a transport (tcp, tcp+tls, udp, unix) URL.
39 33
 func IsTransportURL(str string) bool {
40 34
 	return checkURL(str, "transport")
... ...
@@ -27,20 +27,6 @@ var (
27 27
 	}
28 28
 )
29 29
 
30
-func TestValidGitTransport(t *testing.T) {
31
-	for _, url := range gitUrls {
32
-		if !IsGitTransport(url) {
33
-			t.Fatalf("%q should be detected as valid Git prefix", url)
34
-		}
35
-	}
36
-
37
-	for _, url := range incompleteGitUrls {
38
-		if IsGitTransport(url) {
39
-			t.Fatalf("%q should not be detected as valid Git prefix", url)
40
-		}
41
-	}
42
-}
43
-
44 30
 func TestIsGIT(t *testing.T) {
45 31
 	for _, url := range gitUrls {
46 32
 		if !IsGitURL(url) {