mirror of
https://github.com/golang/go
synced 2024-11-18 11:55:01 -07:00
cmd/go: simplify/fix handling private github repos
Before Go 1.4, the traditional way to work with a private Github repository was to run something similar the following: ``` git config --global url."git@github.com:".insteadOf "https://github.com/" ``` It would allow go get and friends to transparently work as expected, automatically rewriting https URLs to use SSH for auth. This worked both when pushing and pulling. In Go 1.4 this broke, now requiring the use of `go get -f` instead of `go get` in order to fetch private repositories. This seems neither intended nor practical, as it requires changing a lot of tooling. So just use `git config remote.origin.url` instead of `git remote -v` as this reflects the actual substitution intended in the `insteadOf` config directive. Also remove now useless parsing. Also add a check against supported schemes to avoid errors in later commands using this URL and expecting such a scheme. Fixes #9697 Change-Id: I907327f83504302288f913a68f8222a5c2d673ee Reviewed-on: https://go-review.googlesource.com/3504 Reviewed-by: Andrew Gerrand <adg@golang.org>
This commit is contained in:
parent
ea1306a150
commit
668762c570
@ -122,32 +122,19 @@ var vcsGit = &vcsCmd{
|
||||
}
|
||||
|
||||
func gitRemoteRepo(vcsGit *vcsCmd, rootDir string) (remoteRepo string, err error) {
|
||||
outb, err := vcsGit.runOutput(rootDir, "remote -v")
|
||||
cmd := "config remote.origin.url"
|
||||
errParse := errors.New("unable to parse output of git " + cmd)
|
||||
outb, err := vcsGit.runOutput(rootDir, cmd)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
out := string(outb)
|
||||
|
||||
// Expect:
|
||||
// origin https://github.com/rsc/pdf (fetch)
|
||||
// origin https://github.com/rsc/pdf (push)
|
||||
// use first line only.
|
||||
|
||||
if !strings.HasPrefix(out, "origin\t") {
|
||||
return "", fmt.Errorf("unable to parse output of git remote -v")
|
||||
repoUrl := strings.TrimSpace(string(outb))
|
||||
for _, s := range vcsGit.scheme {
|
||||
if strings.HasPrefix(repoUrl, s) {
|
||||
return repoUrl, nil
|
||||
}
|
||||
}
|
||||
out = strings.TrimPrefix(out, "origin\t")
|
||||
i := strings.Index(out, "\n")
|
||||
if i < 0 {
|
||||
return "", fmt.Errorf("unable to parse output of git remote -v")
|
||||
}
|
||||
out = out[:i]
|
||||
i = strings.LastIndex(out, " ")
|
||||
if i < 0 {
|
||||
return "", fmt.Errorf("unable to parse output of git remote -v")
|
||||
}
|
||||
out = out[:i]
|
||||
return strings.TrimSpace(string(out)), nil
|
||||
return "", errParse
|
||||
}
|
||||
|
||||
// vcsBzr describes how to use Bazaar.
|
||||
|
Loading…
Reference in New Issue
Block a user