diff --git a/cli/command/image/build/internal/git/gitutils.go b/cli/command/image/build/internal/git/gitutils.go index cfcf648725..8c39d33c66 100644 --- a/cli/command/image/build/internal/git/gitutils.go +++ b/cli/command/image/build/internal/git/gitutils.go @@ -10,7 +10,6 @@ import ( "strings" "github.com/docker/docker/pkg/symlink" - "github.com/docker/docker/pkg/urlutil" "github.com/pkg/errors" ) @@ -135,7 +134,7 @@ func fetchArgs(remoteURL string, ref string) []string { // Check if a given git URL supports a shallow git clone, // i.e. it is a non-HTTP server or a smart HTTP server. func supportsShallowClone(remoteURL string) bool { - if urlutil.IsURL(remoteURL) { + if scheme := getScheme(remoteURL); scheme == "http" || scheme == "https" { // Check if the HTTP server is smart // Smart servers must correctly respond to a query for the git-upload-pack service @@ -205,5 +204,24 @@ func git(args ...string) ([]byte, error) { // isGitTransport returns true if the provided str is a git transport by inspecting // the prefix of the string for known protocols used in git. func isGitTransport(str string) bool { - return urlutil.IsURL(str) || strings.HasPrefix(str, "git://") || strings.HasPrefix(str, "git@") + if strings.HasPrefix(str, "git@") { + return true + } + + switch getScheme(str) { + case "git", "http", "https": + return true + } + + return false +} + +// getScheme returns addresses' scheme in lowercase, or an empty +// string in case address is an invalid URL. +func getScheme(address string) string { + u, err := url.Parse(address) + if err != nil { + return "" + } + return u.Scheme } diff --git a/cli/command/image/build/internal/git/gitutils_test.go b/cli/command/image/build/internal/git/gitutils_test.go index 02d6c63ea5..aa9e052474 100644 --- a/cli/command/image/build/internal/git/gitutils_test.go +++ b/cli/command/image/build/internal/git/gitutils_test.go @@ -24,6 +24,14 @@ func TestParseRemoteURL(t *testing.T) { url string expected gitRepo }{ + { + doc: "git scheme uppercase, no url-fragment", + url: "GIT://github.com/user/repo.git", + expected: gitRepo{ + remote: "git://github.com/user/repo.git", + ref: "master", + }, + }, { doc: "git scheme, no url-fragment", url: "git://github.com/user/repo.git",