Skip to content

Commit 6ab861f

Browse files
committed
Refactor SSH agent logic
1 parent f90ed64 commit 6ab861f

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

base/libgit2/callbacks.jl

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -56,22 +56,16 @@ function authenticate_ssh(libgit2credptr::Ptr{Ptr{Void}}, p::CredentialPayload,
5656
creds.pass = ""
5757
end
5858

59-
# Note: The same SSHCredentials can be used to authenticate separate requests using the
60-
# same credential cache. e.g. using Pkg.update when there are two private packages.
61-
errcls, errmsg = Error.last_error()
62-
if errcls != Error.None
63-
# Check if we used ssh-agent
64-
if p.use_ssh_agent == 'U'
65-
p.use_ssh_agent = 'E' # reported ssh-agent error, disables ssh agent use for the future
66-
end
67-
end
68-
6959
# first try ssh-agent if credentials support its usage
70-
if p.use_ssh_agent == 'Y' || p.use_ssh_agent == 'U'
60+
if p.use_ssh_agent == 'Y'
7161
err = ccall((:git_cred_ssh_key_from_agent, :libgit2), Cint,
72-
(Ptr{Ptr{Void}}, Cstring), libgit2credptr, username_ptr)
73-
p.use_ssh_agent = 'U' # used ssh-agent only one time
74-
err == 0 && return Cint(0)
62+
(Ptr{Ptr{Void}}, Cstring), libgit2credptr, username_ptr)
63+
if err == 0
64+
p.use_ssh_agent = 'U' # used ssh-agent only one time
65+
return Cint(0)
66+
else
67+
p.use_ssh_agent = 'E'
68+
end
7569
end
7670

7771
if creds.prompt_if_incorrect

0 commit comments

Comments
 (0)