@@ -2,12 +2,12 @@ package gitutil
22
33import (
44 "context"
5- "net/url"
65 "path/filepath"
76 "strings"
87
98 "github.com/docker/buildx/util/osutil"
109 bkgitutil "github.com/moby/buildkit/util/gitutil"
10+ bkurlutil "github.com/moby/buildkit/util/urlutil"
1111 "github.com/pkg/errors"
1212)
1313
@@ -62,16 +62,16 @@ func (cli *GitCLI) RemoteURL(ctx context.Context) (string, error) {
6262 // Try default remote based on remote tracking branch.
6363 if remote , err := cli .currentRemote (ctx ); err == nil && remote != "" {
6464 if ru , err := cli .clean (cli .Run (ctx , "remote" , "get-url" , remote )); err == nil && ru != "" {
65- return stripCredentials (ru ), nil
65+ return bkurlutil . RedactCredentials (ru ), nil
6666 }
6767 }
6868 // Next try to get the remote URL from the origin remote first.
6969 if ru , err := cli .clean (cli .Run (ctx , "remote" , "get-url" , "origin" )); err == nil && ru != "" {
70- return stripCredentials (ru ), nil
70+ return bkurlutil . RedactCredentials (ru ), nil
7171 }
7272 // If that fails, try to get the remote URL from the upstream remote.
7373 if ru , err := cli .clean (cli .Run (ctx , "remote" , "get-url" , "upstream" )); err == nil && ru != "" {
74- return stripCredentials (ru ), nil
74+ return bkurlutil . RedactCredentials (ru ), nil
7575 }
7676 return "" , errors .New ("no remote URL found for either origin or upstream" )
7777}
@@ -135,16 +135,3 @@ func IsUnknownRevision(err error) bool {
135135 errMsg := strings .ToLower (err .Error ())
136136 return strings .Contains (errMsg , "unknown revision or path not in the working tree" ) || strings .Contains (errMsg , "bad revision" )
137137}
138-
139- // stripCredentials takes a URL and strips username and password from it.
140- // e.g. "https://user:password@host.tld/path.git" will be changed to
141- // "https://host.tld/path.git".
142- // TODO: remove this function once fix from BuildKit is vendored here
143- func stripCredentials (s string ) string {
144- ru , err := url .Parse (s )
145- if err != nil {
146- return s // string is not a URL, just return it
147- }
148- ru .User = nil
149- return ru .String ()
150- }
0 commit comments