diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2017-05-04 10:17:15 +0200 |
---|---|---|
committer | Máximo Cuadros <mcuadros@gmail.com> | 2017-05-04 10:17:15 +0200 |
commit | b8b61e74469e0d2662e7d690eee14893f91fe259 (patch) | |
tree | 1933fe53200d98ad2c557d034609408641ce2900 /plumbing/transport/ssh/auth_method.go | |
parent | 40fa5882a2c73f8c075403b7ec85870f04deda07 (diff) | |
parent | e80cdbabb92a1ec35ffad536f52d3ff04b548fd1 (diff) | |
download | go-git-b8b61e74469e0d2662e7d690eee14893f91fe259.tar.gz |
Merge branch 'master' of github.com:src-d/go-git into commit
Diffstat (limited to 'plumbing/transport/ssh/auth_method.go')
-rw-r--r-- | plumbing/transport/ssh/auth_method.go | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/plumbing/transport/ssh/auth_method.go b/plumbing/transport/ssh/auth_method.go index a3e1ad1..84dfe14 100644 --- a/plumbing/transport/ssh/auth_method.go +++ b/plumbing/transport/ssh/auth_method.go @@ -179,9 +179,14 @@ type PublicKeysCallback struct { // NewSSHAgentAuth returns a PublicKeysCallback based on a SSH agent, it opens // a pipe with the SSH agent and uses the pipe as the implementer of the public // key callback function. -func NewSSHAgentAuth(user string) (AuthMethod, error) { - if user == "" { - user = DefaultUsername +func NewSSHAgentAuth(u string) (AuthMethod, error) { + if u == "" { + usr, err := user.Current() + if err != nil { + return nil, fmt.Errorf("error getting current user: %q", err) + } + + u = usr.Username } sshAgentAddr := os.Getenv("SSH_AUTH_SOCK") @@ -195,7 +200,7 @@ func NewSSHAgentAuth(user string) (AuthMethod, error) { } return &PublicKeysCallback{ - User: user, + User: u, Callback: agent.NewClient(pipe).Signers, }, nil } |