@@ -481,6 +481,11 @@ func main() {
481
481
if * flPassword != "" && * flPasswordFile != "" {
482
482
handleConfigError (log , true , "ERROR: only one of --password and --password-file may be specified" )
483
483
}
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
+ }
484
489
} else {
485
490
if * flPassword != "" {
486
491
handleConfigError (log , true , "ERROR: --password may only be specified when --username is specified" )
@@ -564,6 +569,21 @@ func main() {
564
569
absTouchFile := makeAbsPath (* flTouchFile , absRoot )
565
570
566
571
// 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
+ }
567
587
if * flUsername != "" {
568
588
cred := credential {
569
589
URL : * flRepo ,
@@ -1535,7 +1555,7 @@ func (git *repoSync) currentWorktree() (worktree, error) {
1535
1555
// and tries to clean up any detritus. This function returns whether the
1536
1556
// current hash has changed and what the new hash is.
1537
1557
func (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 ) )
1539
1559
1540
1560
if err := refreshCreds (ctx ); err != nil {
1541
1561
return false , "" , fmt .Errorf ("credential refresh failed: %w" , err )
@@ -1660,7 +1680,7 @@ func (git *repoSync) SyncRepo(ctx context.Context, refreshCreds func(context.Con
1660
1680
1661
1681
// fetch retrieves the specified ref from the upstream repo.
1662
1682
func (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 ) )
1664
1684
1665
1685
// Fetch the ref and do some cleanup, setting or un-setting the repo's
1666
1686
// shallow flag as appropriate.
@@ -1711,7 +1731,7 @@ func md5sum(s string) string {
1711
1731
1712
1732
// StoreCredentials stores a username and password for later use.
1713
1733
func (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 ) )
1715
1735
git .log .V (9 ).Info ("md5 of credential" , "url" , url , "username" , md5sum (username ), "password" , md5sum (password ))
1716
1736
1717
1737
creds := fmt .Sprintf ("url=%v\n username=%v\n password=%v\n " , url , username , password )
0 commit comments