1
0
mirror of https://github.com/golang/go synced 2024-11-18 14:34:39 -07:00

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

Also make 'cmd' a const, because it is actually immutable.
This commit is contained in:
Jes Cok 2023-09-22 12:59:45 +08:00
parent 795414d1c6
commit f6698174f5

View File

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