]> Cypherpunks.ru repositories - gostls13.git/commitdiff
cmd/go: set global .gitconfig location more robustly in tests
authorBryan C. Mills <bcmills@google.com>
Thu, 7 Dec 2023 15:24:55 +0000 (10:24 -0500)
committerBryan Mills <bcmills@google.com>
Thu, 7 Dec 2023 16:37:00 +0000 (16:37 +0000)
Also confirm that setting the location actually worked before
proceeding with the rest of the test.

This fixes a test failure with git versions older than 2.32.0.

Updates #53955.
Fixes #64603.

Change-Id: I1a954975a3d8300e8b4dca045d3a15438a0407ec
Cq-Include-Trybots: luci.golang.try:gotip-linux-amd64-longtest,gotip-windows-amd64-longtest
Reviewed-on: https://go-review.googlesource.com/c/go/+/548215
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Russ Cox <rsc@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
Run-TryBot: Bryan Mills <bcmills@google.com>

src/cmd/go/testdata/script/get_issue53955.txt
src/cmd/go/testdata/script/mod_download_git_bareRepository.txt
src/cmd/go/testdata/script/mod_download_git_decorate_full.txt
src/cmd/go/testdata/script/mod_download_issue51114.txt
src/cmd/go/testdata/script/mod_download_private_vcs.txt

index c6d45d5c5088afbbf47ce47a44736087ba7860af..685c6facaa93b7222964acf6c9b5a3eba06d3b7d 100644 (file)
@@ -7,7 +7,16 @@
 [!git] skip
 [!net:github.com] skip 'does not actually use github.com because of insteadOf, but silence network check just in case'
 
-env GIT_CONFIG_GLOBAL=$WORK/.gitconfig
+# Redirect git to a test-specific .gitconfig.
+# GIT_CONFIG_GLOBAL suffices for git 2.32.0 and newer.
+# For older git versions we also set $HOME.
+env GIT_CONFIG_GLOBAL=$WORK${/}home${/}gopher${/}.gitconfig
+env HOME=$WORK${/}home${/}gopher
+exec git config --global --show-origin user.name
+stdout 'Go Gopher'
+
+# Inject a local repo in place of a remote one, so that we can
+# add commits to the repo partway through the test.
 env GIT_ALLOW_PROTOCOL=file
 env GOPRIVATE=github.com/golang/issue53955
 
@@ -64,4 +73,7 @@ package issue53955
 module m
 
 go 1.18
--- $WORK/.gitconfig --
+-- $WORK/home/gopher/.gitconfig --
+[user]
+       name = Go Gopher
+       email = gopher@golang.org
index 8050461c658da7bff4d2c58535f6b44ebe4e25c2..a61283ca49b646ea0ffe24d2f2313cea1781ae7f 100644 (file)
@@ -1,8 +1,14 @@
 [short] skip
 [!git] skip
-[!GOOS:linux] skip  # Uses XDG_CONFIG_HOME
 
-env GIT_CONFIG_GLOBAL=$WORK/.gitconfig
+# Redirect git to a test-specific .gitconfig.
+# GIT_CONFIG_GLOBAL suffices for git 2.32.0 and newer.
+# For older git versions we also set $HOME.
+env GIT_CONFIG_GLOBAL=$WORK${/}home${/}gopher${/}.gitconfig
+env HOME=$WORK${/}home${/}gopher
+exec git config --global --show-origin user.name
+stdout 'Go Gopher'
+
 env GOPRIVATE=vcs-test.golang.org
 
 go mod download -x
@@ -14,6 +20,9 @@ go 1.18
 
 require vcs-test.golang.org/git/gitrepo1.git v1.2.3
 
--- $WORK/.gitconfig --
+-- $WORK/home/gopher/.gitconfig --
+[user]
+       name = Go Gopher
+       email = gopher@golang.org
 [safe]
-bareRepository = explicit
+       bareRepository = explicit
index 080ccf072e02715c38e5cef665f17894a046ecd5..9afd347746641e3684ec4c6e63dbee68413d51fe 100644 (file)
@@ -3,12 +3,15 @@ env GO111MODULE=on
 [short] skip
 [!git] skip
 
-env GOPROXY=direct
-env HOME=$WORK/home/gopher
-
+# Redirect git to a test-specific .gitconfig.
+# GIT_CONFIG_GLOBAL suffices for git 2.32.0 and newer.
+# For older git versions we also set $HOME.
+env GIT_CONFIG_GLOBAL=$WORK${/}home${/}gopher${/}.gitconfig
+env HOME=$WORK${/}home${/}gopher
+exec git config --global --show-origin user.name
+stdout 'Go Gopher'
 
-go env GOPROXY
-stdout 'direct'
+env GOPROXY=direct
 
 exec git config --get log.decorate
 stdout 'full'
@@ -24,5 +27,8 @@ 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 --
+[user]
+       name = Go Gopher
+       email = gopher@golang.org
 [log]
        decorate = full
index 4d274d61a97c04dd38ac3db297aecf89c5e6a4d8..a28d467bb8b1ce44f5b9ebda4d6b439196459d72 100644 (file)
@@ -1,8 +1,14 @@
 [!net:github.com] skip
 [!git] skip
-[!GOOS:linux] skip  # Uses XDG_CONFIG_HOME
 
-env GIT_CONFIG_GLOBAL=$WORK/.gitconfig
+# Redirect git to a test-specific .gitconfig.
+# GIT_CONFIG_GLOBAL suffices for git 2.32.0 and newer.
+# For older git versions we also set $HOME.
+env GIT_CONFIG_GLOBAL=$WORK${/}home${/}gopher${/}.gitconfig
+env HOME=$WORK${/}home${/}gopher
+exec git config --global --show-origin user.name
+stdout 'Go Gopher'
+
 env GOPROXY=direct
 
 ! go mod download
@@ -15,6 +21,9 @@ go 1.18
 
 require github.com/golang/notexist/subdir v0.1.0
 
--- $WORK/.gitconfig --
+-- $WORK/home/gopher/.gitconfig --
+[user]
+       name = Go Gopher
+       email = gopher@golang.org
 [url "git@github.com:"]
        insteadOf = https://github.com/
index 2f72a4213a3c3bc6cb5442247ee4de7d0ff3afb8..5c8d93a978d7fe18782de963a64c987d6251c4d8 100644 (file)
@@ -5,6 +5,14 @@ env GO111MODULE=on
 [!git] skip
 env GOPROXY=direct
 
+# Redirect git to a test-specific .gitconfig.
+# GIT_CONFIG_GLOBAL suffices for git 2.32.0 and newer.
+# For older git versions we also set $HOME.
+env GIT_CONFIG_GLOBAL=$WORK${/}home${/}gopher${/}.gitconfig
+env HOME=$WORK${/}home${/}gopher
+exec git config --global --show-origin user.name
+stdout 'Go Gopher'
+
 ! go mod download github.com/golang/nonexist@latest
 stderr 'Confirm the import path was entered correctly.'
 stderr 'If this is a private repository, see https://golang.org/doc/faq#git_https for additional information.'
@@ -27,7 +35,7 @@ stderr '^If this is a private repository, see https://golang.org/doc/faq#git_htt
 # Test that Git clone errors will be shown to the user instead of a generic
 # "unknown revision" error. To do this we want to force git ls-remote to return
 # an error we don't already have special handling for. See golang/go#42751.
-env HOME=$WORK${/}home${/}gopher
+exec git config --global url.git@github.com.insteadOf https://github.com/
 env GIT_SSH_COMMAND=false
 ! go install github.com/golang/nonexist@master
 stderr 'fatal: Could not read from remote repository.'
@@ -35,5 +43,6 @@ stderr 'fatal: Could not read from remote repository.'
 ! stdout .
 
 -- $WORK/home/gopher/.gitconfig --
-[url "git@github.com:"]
-       insteadOf = https://github.com/
+[user]
+       name = Go Gopher
+       email = gopher@golang.org