urlutil.IsUrl() was merely checking if the url had a http(s)://
prefix, which is just as well handled through using url.Parse()
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
| ... | ... |
@@ -10,7 +10,6 @@ import ( |
| 10 | 10 |
"strings" |
| 11 | 11 |
|
| 12 | 12 |
"github.com/docker/docker/pkg/symlink" |
| 13 |
- "github.com/docker/docker/pkg/urlutil" |
|
| 14 | 13 |
"github.com/pkg/errors" |
| 15 | 14 |
) |
| 16 | 15 |
|
| ... | ... |
@@ -135,7 +134,7 @@ func fetchArgs(remoteURL string, ref string) []string {
|
| 135 | 135 |
// Check if a given git URL supports a shallow git clone, |
| 136 | 136 |
// i.e. it is a non-HTTP server or a smart HTTP server. |
| 137 | 137 |
func supportsShallowClone(remoteURL string) bool {
|
| 138 |
- if urlutil.IsURL(remoteURL) {
|
|
| 138 |
+ if scheme := getScheme(remoteURL); scheme == "http" || scheme == "https" {
|
|
| 139 | 139 |
// Check if the HTTP server is smart |
| 140 | 140 |
|
| 141 | 141 |
// Smart servers must correctly respond to a query for the git-upload-pack service |
| ... | ... |
@@ -205,5 +204,24 @@ func git(args ...string) ([]byte, error) {
|
| 205 | 205 |
// isGitTransport returns true if the provided str is a git transport by inspecting |
| 206 | 206 |
// the prefix of the string for known protocols used in git. |
| 207 | 207 |
func isGitTransport(str string) bool {
|
| 208 |
- return urlutil.IsURL(str) || strings.HasPrefix(str, "git://") || strings.HasPrefix(str, "git@") |
|
| 208 |
+ if strings.HasPrefix(str, "git@") {
|
|
| 209 |
+ return true |
|
| 210 |
+ } |
|
| 211 |
+ |
|
| 212 |
+ switch getScheme(str) {
|
|
| 213 |
+ case "git", "http", "https": |
|
| 214 |
+ return true |
|
| 215 |
+ } |
|
| 216 |
+ |
|
| 217 |
+ return false |
|
| 218 |
+} |
|
| 219 |
+ |
|
| 220 |
+// getScheme returns addresses' scheme in lowercase, or an empty |
|
| 221 |
+// string in case address is an invalid URL. |
|
| 222 |
+func getScheme(address string) string {
|
|
| 223 |
+ u, err := url.Parse(address) |
|
| 224 |
+ if err != nil {
|
|
| 225 |
+ return "" |
|
| 226 |
+ } |
|
| 227 |
+ return u.Scheme |
|
| 209 | 228 |
} |
| ... | ... |
@@ -25,6 +25,14 @@ func TestParseRemoteURL(t *testing.T) {
|
| 25 | 25 |
expected gitRepo |
| 26 | 26 |
}{
|
| 27 | 27 |
{
|
| 28 |
+ doc: "git scheme uppercase, no url-fragment", |
|
| 29 |
+ url: "GIT://github.com/user/repo.git", |
|
| 30 |
+ expected: gitRepo{
|
|
| 31 |
+ remote: "git://github.com/user/repo.git", |
|
| 32 |
+ ref: "master", |
|
| 33 |
+ }, |
|
| 34 |
+ }, |
|
| 35 |
+ {
|
|
| 28 | 36 |
doc: "git scheme, no url-fragment", |
| 29 | 37 |
url: "git://github.com/user/repo.git", |
| 30 | 38 |
expected: gitRepo{
|