From 77cc1c0defaf4cd6c38221504b29ad125aae9ac7 Mon Sep 17 00:00:00 2001 From: hidu Date: Thu, 3 Mar 2022 13:33:38 +0800 Subject: [release-branch.go1.17] cmd/go: pass --no-decorate when listing git tags for a commit This avoids a parse error when the user's global .gitconfig sets log.decorate to true. Updates #51312. Fixes #51351. Change-Id: Ic47b0f604c0c3a404ec50d6e09f4e138045ac2f2 Reviewed-on: https://go-review.googlesource.com/c/go/+/387835 Run-TryBot: Bryan Mills Auto-Submit: Bryan Mills Reviewed-by: Bryan Mills TryBot-Result: Gopher Robot Reviewed-by: Dmitri Shuralyov Reviewed-by: David Chase Reviewed-by: Dmitri Shuralyov (cherry picked from commit a30f4346674ec43bf576e6f56a9cd1c7ca482e1f) Reviewed-on: https://go-review.googlesource.com/c/go/+/414875 --- src/cmd/go/internal/modfetch/codehost/git.go | 2 +- .../script/mod_download_git_decorate_full.txt | 28 ++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 src/cmd/go/testdata/script/mod_download_git_decorate_full.txt diff --git a/src/cmd/go/internal/modfetch/codehost/git.go b/src/cmd/go/internal/modfetch/codehost/git.go index 4d4964edf44..55aecd04c98 100644 --- a/src/cmd/go/internal/modfetch/codehost/git.go +++ b/src/cmd/go/internal/modfetch/codehost/git.go @@ -440,7 +440,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} } diff --git a/src/cmd/go/testdata/script/mod_download_git_decorate_full.txt b/src/cmd/go/testdata/script/mod_download_git_decorate_full.txt new file mode 100644 index 00000000000..3b19acc1b15 --- /dev/null +++ b/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 \ No newline at end of file -- cgit v1.2.3-54-g00ecf