Skip to content

Commit ad6b187

Browse files
committed
netrc: consider same machine may have different login names
1 parent 3e7401c commit ad6b187

File tree

7 files changed

+26
-16
lines changed

7 files changed

+26
-16
lines changed

config/netrc.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ import (
88
)
99

1010
type netrcfinder interface {
11-
FindMachine(string) *netrc.Machine
11+
FindMachine(string, string) *netrc.Machine
1212
}
1313

1414
type noNetrc struct{}
1515

16-
func (n *noNetrc) FindMachine(host string) *netrc.Machine {
16+
func (n *noNetrc) FindMachine(host string, loginName string) *netrc.Machine {
1717
return nil
1818
}
1919

creds/netrc.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
)
1414

1515
type NetrcFinder interface {
16-
FindMachine(string) *netrc.Machine
16+
FindMachine(string, string) *netrc.Machine
1717
}
1818

1919
func ParseNetrc(osEnv config.Environment) (NetrcFinder, string, error) {
@@ -33,7 +33,7 @@ func ParseNetrc(osEnv config.Environment) (NetrcFinder, string, error) {
3333

3434
type noFinder struct{}
3535

36-
func (f *noFinder) FindMachine(host string) *netrc.Machine {
36+
func (f *noFinder) FindMachine(host string, loginName string) *netrc.Machine {
3737
return nil
3838
}
3939

@@ -72,7 +72,7 @@ func (c *netrcCredentialHelper) Fill(what Creds) (Creds, error) {
7272
if c.skip[host] {
7373
return nil, credHelperNoOp
7474
}
75-
if machine := c.netrcFinder.FindMachine(host); machine != nil {
75+
if machine := c.netrcFinder.FindMachine(host, what["username"]); machine != nil {
7676
creds := make(Creds)
7777
creds["username"] = machine.Login
7878
creds["password"] = machine.Password
@@ -81,8 +81,8 @@ func (c *netrcCredentialHelper) Fill(what Creds) (Creds, error) {
8181
creds["scheme"] = what["scheme"]
8282
creds["path"] = what["path"]
8383
creds["source"] = "netrc"
84-
tracerx.Printf("netrc: git credential fill (%q, %q, %q)",
85-
what["protocol"], what["host"], what["path"])
84+
tracerx.Printf("netrc: git credential fill (%q, %q, %q, %q)",
85+
what["protocol"], what["host"], machine.Login, what["path"])
8686
return creds, nil
8787
}
8888

creds/netrc_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func TestNetrcWithBadHost(t *testing.T) {
7474

7575
type fakeNetrc struct{}
7676

77-
func (n *fakeNetrc) FindMachine(host string) *netrc.Machine {
77+
func (n *fakeNetrc) FindMachine(host string, loginName string) *netrc.Machine {
7878
if strings.Contains(host, "netrc") {
7979
return &netrc.Machine{Login: "abc", Password: "def"}
8080
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
github.com/avast/retry-go v2.4.2+incompatible
77
github.com/dpotapov/go-spnego v0.0.0-20210315154721-298b63a54430
88
github.com/git-lfs/gitobj/v2 v2.0.2
9-
github.com/git-lfs/go-netrc v0.0.0-20180525200031-e0e9ca483a18
9+
github.com/git-lfs/go-netrc v0.0.0-20210914205454-f0c862dd687a
1010
github.com/git-lfs/pktline v0.0.0-20210330133718-06e9096e2825
1111
github.com/git-lfs/wildmatch/v2 v2.0.1
1212
github.com/inconshreveable/mousetrap v1.0.0 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ github.com/git-lfs/gitobj/v2 v2.0.2 h1:p8rWlhEyiSsC+4Qc+EdufySatf8sDtvJIrHAHgf7A
1111
github.com/git-lfs/gitobj/v2 v2.0.2/go.mod h1:q6aqxl6Uu3gWsip5GEKpw+7459F97er8COmU45ncAxw=
1212
github.com/git-lfs/go-netrc v0.0.0-20180525200031-e0e9ca483a18 h1:7Th0eBA4rT8WJNiM1vppjaIv9W5WJinhpbCJvRJxloI=
1313
github.com/git-lfs/go-netrc v0.0.0-20180525200031-e0e9ca483a18/go.mod h1:70O4NAtvWn1jW8V8V+OKrJJYcxDLTmIozfi2fmSz5SI=
14+
github.com/git-lfs/go-netrc v0.0.0-20210914205454-f0c862dd687a h1:6pskVZacdMUL93pCpMAYnMDLjH1yDFhssPYGe32sjdk=
15+
github.com/git-lfs/go-netrc v0.0.0-20210914205454-f0c862dd687a/go.mod h1:70O4NAtvWn1jW8V8V+OKrJJYcxDLTmIozfi2fmSz5SI=
1416
github.com/git-lfs/pktline v0.0.0-20210330133718-06e9096e2825 h1:riQhgheTL7tMF4d5raz9t3+IzoR1i1wqxE1kZC6dY+U=
1517
github.com/git-lfs/pktline v0.0.0-20210330133718-06e9096e2825/go.mod h1:fenKRzpXDjNpsIBhuhUzvjCKlDjKam0boRAenTE0Q6A=
1618
github.com/git-lfs/wildmatch/v2 v2.0.1 h1:Ds+aobrV5bK0wStILUOn9irllPyf9qrFETbKzwzoER8=

vendor/github.com/git-lfs/go-netrc/netrc/netrc.go

Lines changed: 14 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/modules.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ github.com/git-lfs/gitobj/v2
1313
github.com/git-lfs/gitobj/v2/errors
1414
github.com/git-lfs/gitobj/v2/pack
1515
github.com/git-lfs/gitobj/v2/storage
16-
# github.com/git-lfs/go-netrc v0.0.0-20180525200031-e0e9ca483a18
16+
# github.com/git-lfs/go-netrc v0.0.0-20210914205454-f0c862dd687a
1717
github.com/git-lfs/go-netrc/netrc
1818
# github.com/git-lfs/pktline v0.0.0-20210330133718-06e9096e2825
1919
github.com/git-lfs/pktline

0 commit comments

Comments
 (0)