Skip to content

Commit

Permalink
cmd/go: pass --no-decorate when listing git tags for a commit
Browse files Browse the repository at this point in the history
This avoids a parse error when the user's global .gitconfig sets
log.decorate to true.

Fixes #51312.

Change-Id: Ic47b0f604c0c3a404ec50d6e09f4e138045ac2f2
Reviewed-on: https://go-review.googlesource.com/c/go/+/387835
Run-TryBot: Bryan Mills <bcmills@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
  • Loading branch information
hidu authored and gopherbot committed Jun 28, 2022
1 parent 3580ef9 commit a30f434
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/cmd/go/internal/modfetch/codehost/git.go
Expand Up @@ -447,7 +447,7 @@ func (r *gitRepo) fetchRefsLocked() error {
// statLocal returns a RevInfo describing rev in the local git repository.
// It uses version as info.Version.
func (r *gitRepo) statLocal(version, rev string) (*RevInfo, error) {
out, err := Run(r.dir, "git", "-c", "log.showsignature=false", "log", "-n1", "--format=format:%H %ct %D", rev, "--")
out, err := Run(r.dir, "git", "-c", "log.showsignature=false", "log", "--no-decorate", "-n1", "--format=format:%H %ct %D", rev, "--")
if err != nil {
return nil, &UnknownRevisionError{Rev: rev}
}
Expand Down
28 changes: 28 additions & 0 deletions src/cmd/go/testdata/script/mod_download_git_decorate_full.txt
@@ -0,0 +1,28 @@
env GO111MODULE=on

[!net] skip
[!exec:git] skip

env GOPROXY=direct
env HOME=$WORK/home/gopher


go env GOPROXY
stdout 'direct'

exec git config --get log.decorate
stdout 'full'

# Test that Git log with user's global config '~/gitconfig' has log.decorate=full
# go mod download has an error 'v1.x.y is not a tag'
# with go1.16.14:
# `go1.16.14 list -m vcs-test.golang.org/git/gitrepo1.git@v1.2.3`
# will output with error:
# go list -m: vcs-test.golang.org/git/gitrepo1.git@v1.2.3: invalid version: unknown revision v1.2.3
# See golang/go#51312.
go list -m vcs-test.golang.org/git/gitrepo1.git@v1.2.3
stdout 'vcs-test.golang.org/git/gitrepo1.git v1.2.3'

-- $WORK/home/gopher/.gitconfig --
[log]
decorate = full

0 comments on commit a30f434

Please sign in to comment.