Skip to content

Commit e9f3c9b

Browse files
Bryan C. Millsgopherbot
Bryan C. Mills
authored andcommitted
[release-branch.go1.21] cmd/go: set global .gitconfig location more robustly in tests
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. For #53955. For #64603. Fixes #64586 Change-Id: I1a954975a3d8300e8b4dca045d3a15438a0407ec Reviewed-on: https://go-review.googlesource.com/c/go/+/548215 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Russ Cox <[email protected]> Reviewed-by: Michael Matloob <[email protected]> Run-TryBot: Bryan Mills <[email protected]> Reviewed-on: https://go-review.googlesource.com/c/go/+/585816 Reviewed-by: Sam Thanawalla <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> Auto-Submit: Dmitri Shuralyov <[email protected]> TryBot-Bypass: Dmitri Shuralyov <[email protected]>
1 parent a6023db commit e9f3c9b

5 files changed

+62
-17
lines changed

src/cmd/go/testdata/script/get_issue53955.txt

+14-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,16 @@
77
[!git] skip
88
[!net:github.com] skip 'does not actually use github.com because of insteadOf, but silence network check just in case'
99

10-
env GIT_CONFIG_GLOBAL=$WORK/.gitconfig
10+
# Redirect git to a test-specific .gitconfig.
11+
# GIT_CONFIG_GLOBAL suffices for git 2.32.0 and newer.
12+
# For older git versions we also set $HOME.
13+
env GIT_CONFIG_GLOBAL=$WORK${/}home${/}gopher${/}.gitconfig
14+
env HOME=$WORK${/}home${/}gopher
15+
exec git config --global --show-origin user.name
16+
stdout 'Go Gopher'
17+
18+
# Inject a local repo in place of a remote one, so that we can
19+
# add commits to the repo partway through the test.
1120
env GIT_ALLOW_PROTOCOL=file
1221
env GOPRIVATE=github.com/golang/issue53955
1322

@@ -64,4 +73,7 @@ package issue53955
6473
module m
6574

6675
go 1.18
67-
-- $WORK/.gitconfig --
76+
-- $WORK/home/gopher/.gitconfig --
77+
[user]
78+
name = Go Gopher
79+
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
[short] skip
22
[!git] skip
3-
[!GOOS:linux] skip # Uses XDG_CONFIG_HOME
43

5-
env GIT_CONFIG_GLOBAL=$WORK/.gitconfig
4+
# Redirect git to a test-specific .gitconfig.
5+
# GIT_CONFIG_GLOBAL suffices for git 2.32.0 and newer.
6+
# For older git versions we also set $HOME.
7+
env GIT_CONFIG_GLOBAL=$WORK${/}home${/}gopher${/}.gitconfig
8+
env HOME=$WORK${/}home${/}gopher
9+
exec git config --global --show-origin user.name
10+
stdout 'Go Gopher'
11+
612
env GOPRIVATE=vcs-test.golang.org
713

814
go mod download -x
@@ -14,6 +20,9 @@ go 1.18
1420

1521
require vcs-test.golang.org/git/gitrepo1.git v1.2.3
1622

17-
-- $WORK/.gitconfig --
23+
-- $WORK/home/gopher/.gitconfig --
24+
[user]
25+
name = Go Gopher
26+
1827
[safe]
19-
bareRepository = explicit
28+
bareRepository = explicit

src/cmd/go/testdata/script/mod_download_git_decorate_full.txt

+11-5
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@ env GO111MODULE=on
33
[short] skip
44
[!git] skip
55

6-
env GOPROXY=direct
7-
env HOME=$WORK/home/gopher
8-
6+
# Redirect git to a test-specific .gitconfig.
7+
# GIT_CONFIG_GLOBAL suffices for git 2.32.0 and newer.
8+
# For older git versions we also set $HOME.
9+
env GIT_CONFIG_GLOBAL=$WORK${/}home${/}gopher${/}.gitconfig
10+
env HOME=$WORK${/}home${/}gopher
11+
exec git config --global --show-origin user.name
12+
stdout 'Go Gopher'
913

10-
go env GOPROXY
11-
stdout 'direct'
14+
env GOPROXY=direct
1215

1316
exec git config --get log.decorate
1417
stdout 'full'
@@ -24,5 +27,8 @@ go list -m vcs-test.golang.org/git/[email protected]
2427
stdout 'vcs-test.golang.org/git/gitrepo1.git v1.2.3'
2528

2629
-- $WORK/home/gopher/.gitconfig --
30+
[user]
31+
name = Go Gopher
32+
2733
[log]
2834
decorate = full

src/cmd/go/testdata/script/mod_download_issue51114.txt

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
[!net:github.com] skip
22
[!git] skip
3-
[!GOOS:linux] skip # Uses XDG_CONFIG_HOME
43

5-
env GIT_CONFIG_GLOBAL=$WORK/.gitconfig
4+
# Redirect git to a test-specific .gitconfig.
5+
# GIT_CONFIG_GLOBAL suffices for git 2.32.0 and newer.
6+
# For older git versions we also set $HOME.
7+
env GIT_CONFIG_GLOBAL=$WORK${/}home${/}gopher${/}.gitconfig
8+
env HOME=$WORK${/}home${/}gopher
9+
exec git config --global --show-origin user.name
10+
stdout 'Go Gopher'
11+
612
env GOPROXY=direct
713

814
! go mod download
@@ -15,6 +21,9 @@ go 1.18
1521

1622
require github.com/golang/notexist/subdir v0.1.0
1723

18-
-- $WORK/.gitconfig --
24+
-- $WORK/home/gopher/.gitconfig --
25+
[user]
26+
name = Go Gopher
27+
1928
2029
insteadOf = https://github.com/

src/cmd/go/testdata/script/mod_download_private_vcs.txt

+12-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ env GO111MODULE=on
55
[!git] skip
66
env GOPROXY=direct
77

8+
# Redirect git to a test-specific .gitconfig.
9+
# GIT_CONFIG_GLOBAL suffices for git 2.32.0 and newer.
10+
# For older git versions we also set $HOME.
11+
env GIT_CONFIG_GLOBAL=$WORK${/}home${/}gopher${/}.gitconfig
12+
env HOME=$WORK${/}home${/}gopher
13+
exec git config --global --show-origin user.name
14+
stdout 'Go Gopher'
15+
816
! go mod download github.com/golang/nonexist@latest
917
stderr 'Confirm the import path was entered correctly.'
1018
stderr 'If this is a private repository, see https://golang.org/doc/faq#git_https for additional information.'
@@ -27,13 +35,14 @@ stderr '^If this is a private repository, see https://golang.org/doc/faq#git_htt
2735
# Test that Git clone errors will be shown to the user instead of a generic
2836
# "unknown revision" error. To do this we want to force git ls-remote to return
2937
# an error we don't already have special handling for. See golang/go#42751.
30-
env HOME=$WORK${/}home${/}gopher
38+
exec git config --global [email protected] https://github.com/
3139
env GIT_SSH_COMMAND=false
3240
! go install github.com/golang/nonexist@master
3341
stderr 'fatal: Could not read from remote repository.'
3442
! stderr 'unknown revision'
3543
! stdout .
3644

3745
-- $WORK/home/gopher/.gitconfig --
38-
39-
insteadOf = https://github.com/
46+
[user]
47+
name = Go Gopher
48+

0 commit comments

Comments
 (0)