1
0
mirror of https://github.com/golang/go synced 2024-11-26 16:07:00 -07:00

cmd/go/internal/vcs: don’t new errors ahead of time in gitRemoteRepo

Also make 'cmd' a const for it is in fact immutable.

Change-Id: I3373daa1775e863a378355a355325a7fbdf90485
GitHub-Last-Rev: f6698174f5
GitHub-Pull-Request: golang/go#63155
Reviewed-on: https://go-review.googlesource.com/c/go/+/530395
Auto-Submit: Bryan Mills <bcmills@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
This commit is contained in:
Jes Cok 2023-09-25 15:11:04 +00:00 committed by Gopher Robot
parent 66959a5934
commit 33d3625bf8

View File

@ -283,15 +283,13 @@ var vcsGit = &Cmd{
var scpSyntaxRe = lazyregexp.New(`^(\w+)@([\w.-]+):(.*)$`)
func gitRemoteRepo(vcsGit *Cmd, rootDir string) (remoteRepo string, err error) {
cmd := "config remote.origin.url"
errParse := errors.New("unable to parse output of git " + cmd)
errRemoteOriginNotFound := errors.New("remote origin not found")
const cmd = "config remote.origin.url"
outb, err := vcsGit.run1(rootDir, cmd, nil, false)
if err != nil {
// if it doesn't output any message, it means the config argument is correct,
// but the config value itself doesn't exist
if outb != nil && len(outb) == 0 {
return "", errRemoteOriginNotFound
return "", errors.New("remote origin not found")
}
return "", err
}
@ -323,7 +321,7 @@ func gitRemoteRepo(vcsGit *Cmd, rootDir string) (remoteRepo string, err error) {
return repoURL.String(), nil
}
}
return "", errParse
return "", errors.New("unable to parse output of git " + cmd)
}
func gitStatus(vcsGit *Cmd, rootDir string) (Status, error) {