Use the git remote's credentials if the scheme and host match, so that users don't have to cache the same credentials twice
This commit is contained in:
parent
5dc06970b5
commit
5bcb1602d4
@ -653,7 +653,29 @@ func getCreds(req *http.Request) (Creds, error) {
|
||||
}
|
||||
}
|
||||
|
||||
creds, err := credentials(apiUrl)
|
||||
credsUrl := apiUrl
|
||||
if len(Config.CurrentRemote) > 0 {
|
||||
if u, ok := Config.GitConfig("remote." + Config.CurrentRemote + ".url"); ok {
|
||||
gitRemoteUrl, err := url.Parse(u)
|
||||
|
||||
if err == nil &&
|
||||
gitRemoteUrl.Scheme == apiUrl.Scheme &&
|
||||
gitRemoteUrl.Host == apiUrl.Host {
|
||||
|
||||
if gitRemoteUrl.User != nil {
|
||||
if pass, ok := gitRemoteUrl.User.Password(); ok {
|
||||
fmt.Fprintln(os.Stderr, "warning: current Git remote contains credentials")
|
||||
setRequestAuth(req, gitRemoteUrl.User.Username(), pass)
|
||||
return nil, nil
|
||||
}
|
||||
}
|
||||
|
||||
credsUrl = gitRemoteUrl
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
creds, err := credentials(credsUrl)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user