@@ -3,10 +3,10 @@ package cmd
3
3
import (
4
4
"context"
5
5
"path/filepath"
6
+ "regexp"
6
7
"strings"
7
8
"time"
8
9
9
- "github.com/docker/docker/builder/remotecontext/urlutil"
10
10
"github.com/pkg/errors"
11
11
"github.com/rs/zerolog/log"
12
12
@@ -35,7 +35,7 @@ var ErrCannotUseQueryWithFilePath = errors.New("relative and absolute file paths
35
35
36
36
func maybeCloneGitUrl (ctx context.Context , repoManager cloner , repoRefreshDuration time.Duration , location , vcsUsername string ) (string , error ) {
37
37
result := strings .SplitN (location , "?" , 2 )
38
- if ! urlutil . IsGitURL (result [0 ]) {
38
+ if ! isGitURL (result [0 ]) {
39
39
if len (result ) > 1 {
40
40
return "" , ErrCannotUseQueryWithFilePath
41
41
}
@@ -82,3 +82,26 @@ func maybeCloneGitUrl(ctx context.Context, repoManager cloner, repoRefreshDurati
82
82
83
83
return path , nil
84
84
}
85
+
86
+ func isGitURL (str string ) bool {
87
+ if IsURL (str ) && urlPathWithFragmentSuffix .MatchString (str ) {
88
+ return true
89
+ }
90
+ for _ , prefix := range []string {"git://" , "github.com/" , "git@" } {
91
+ if strings .HasPrefix (str , prefix ) {
92
+ return true
93
+ }
94
+ }
95
+ return false
96
+ }
97
+
98
+ // urlPathWithFragmentSuffix matches fragments to use as Git reference and build
99
+ // context from the Git repository. See IsGitURL for details.
100
+ var urlPathWithFragmentSuffix = regexp .MustCompile (`\.git(?:#.+)?$` )
101
+
102
+ // IsURL returns true if the provided str is an HTTP(S) URL by checking if it
103
+ // has a http:// or https:// scheme. No validation is performed to verify if the
104
+ // URL is well-formed.
105
+ func IsURL (str string ) bool {
106
+ return strings .HasPrefix (str , "https://" ) || strings .HasPrefix (str , "http://" )
107
+ }
0 commit comments