@@ -481,6 +481,11 @@ func main() {
481481 if * flPassword != "" && * flPasswordFile != "" {
482482 handleConfigError (log , true , "ERROR: only one of --password and --password-file may be specified" )
483483 }
484+ if u , err := url .Parse (* flRepo ); err == nil { // it may not even parse as a URL, that's OK
485+ if u .User != nil {
486+ handleConfigError (log , true , "ERROR: credentials may not be specified in --repo when --username is specified" )
487+ }
488+ }
484489 } else {
485490 if * flPassword != "" {
486491 handleConfigError (log , true , "ERROR: --password may only be specified when --username is specified" )
@@ -564,6 +569,21 @@ func main() {
564569 absTouchFile := makeAbsPath (* flTouchFile , absRoot )
565570
566571 // Merge credential sources.
572+ if * flUsername == "" {
573+ // username and user@host URLs are validated as mutually exclusive
574+ if u , err := url .Parse (* flRepo ); err == nil { // it may not even parse as a URL, that's OK
575+ if u .User != nil {
576+ if user := u .User .Username (); user != "" {
577+ * flUsername = user
578+ }
579+ if pass , found := u .User .Password (); found {
580+ * flPassword = pass
581+ }
582+ u .User = nil
583+ * flRepo = u .String ()
584+ }
585+ }
586+ }
567587 if * flUsername != "" {
568588 cred := credential {
569589 URL : * flRepo ,
@@ -1535,7 +1555,7 @@ func (git *repoSync) currentWorktree() (worktree, error) {
15351555// and tries to clean up any detritus. This function returns whether the
15361556// current hash has changed and what the new hash is.
15371557func (git * repoSync ) SyncRepo (ctx context.Context , refreshCreds func (context.Context ) error ) (bool , string , error ) {
1538- git .log .V (3 ).Info ("syncing" , "repo" , git .repo )
1558+ git .log .V (3 ).Info ("syncing" , "repo" , redactURL ( git .repo ) )
15391559
15401560 if err := refreshCreds (ctx ); err != nil {
15411561 return false , "" , fmt .Errorf ("credential refresh failed: %w" , err )
@@ -1660,7 +1680,7 @@ func (git *repoSync) SyncRepo(ctx context.Context, refreshCreds func(context.Con
16601680
16611681// fetch retrieves the specified ref from the upstream repo.
16621682func (git * repoSync ) fetch (ctx context.Context , ref string ) error {
1663- git .log .V (2 ).Info ("fetching" , "ref" , ref , "repo" , git .repo )
1683+ git .log .V (2 ).Info ("fetching" , "ref" , ref , "repo" , redactURL ( git .repo ) )
16641684
16651685 // Fetch the ref and do some cleanup, setting or un-setting the repo's
16661686 // shallow flag as appropriate.
@@ -1711,7 +1731,7 @@ func md5sum(s string) string {
17111731
17121732// StoreCredentials stores a username and password for later use.
17131733func (git * repoSync ) StoreCredentials (ctx context.Context , url , username , password string ) error {
1714- git .log .V (1 ).Info ("storing git credential" , "url" , url )
1734+ git .log .V (1 ).Info ("storing git credential" , "url" , redactURL ( url ) )
17151735 git .log .V (9 ).Info ("md5 of credential" , "url" , url , "username" , md5sum (username ), "password" , md5sum (password ))
17161736
17171737 creds := fmt .Sprintf ("url=%v\n username=%v\n password=%v\n " , url , username , password )
0 commit comments