Merge branch '554-master' into usehttppath-tests

This commit is contained in:
Rick Olson 2015-08-04 12:11:10 -06:00
commit 7ee5f661a8
2 changed files with 25 additions and 2 deletions

@ -653,7 +653,29 @@ func getCreds(req *http.Request) (Creds, error) {
} }
} }
creds, err := credentials(req.URL) 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 { if err != nil {
return nil, err return nil, err
} }

@ -17,7 +17,8 @@ type credentialFunc func(Creds, string) (credentialFetcher, error)
var execCreds credentialFunc var execCreds credentialFunc
func credentials(u *url.URL) (Creds, error) { func credentials(u *url.URL) (Creds, error) {
creds := Creds{"protocol": u.Scheme, "host": u.Host} path := strings.TrimPrefix(u.Path, "/")
creds := Creds{"protocol": u.Scheme, "host": u.Host, "path": path}
cmd, err := execCreds(creds, "fill") cmd, err := execCreds(creds, "fill")
if err != nil { if err != nil {
return nil, err return nil, err