...
1# This test checks that VCS information is stamped into Go binaries by default,
2# controlled with -buildvcs. This test focuses on Mercurial specifics.
3# The Git test covers common functionality.
4
5[!exec:hg] skip
6[short] skip
7env GOBIN=$WORK/gopath/bin
8env oldpath=$PATH
9env TZ=GMT
10env HGRCPATH=$WORK/hgrc
11cd repo/a
12
13# If there's no local repository, there's no VCS info.
14go install
15go version -m $GOBIN/a$GOEXE
16! stdout hgrevision
17stdout '\s+mod\s+example.com/a\s+\(devel\)'
18rm $GOBIN/a$GOEXE
19
20# If there is a repository, but it can't be used for some reason,
21# there should be an error. It should hint about -buildvcs=false.
22cd ..
23mkdir .hg
24env PATH=$WORK${/}fakebin${:}$oldpath
25chmod 0755 $WORK/fakebin/hg
26! exec hg help
27cd a
28! go install
29stderr '^error obtaining VCS status: exit status 1\n\tUse -buildvcs=false to disable VCS stamping.$'
30rm $GOBIN/a$GOEXE
31cd ..
32env PATH=$oldpath
33rm .hg
34
35# An empty repository or one explicitly updated to null uses the null cset ID,
36# and the time is hard set to 1/1/70, regardless of the current time.
37exec hg init
38cd a
39go install
40go version -m $GOBIN/a$GOEXE
41stdout '^\tbuild\tvcs.revision=0000000000000000000000000000000000000000$'
42stdout '^\tbuild\tvcs.time=1970-01-01T00:00:00Z$'
43stdout '^\tbuild\tvcs.modified=true$'
44stdout '\s+mod\s+example.com/a\s+v0.0.0-19700101000000-000000000000\+dirty'
45cd ..
46
47# Revision and commit time are tagged for repositories with commits.
48exec hg add a README
49exec hg commit -m 'initial commit' --user test-user --date '2024-07-31T01:21:27+00:00'
50exec hg tag v1.2.3
51# Switch back to the tagged branch.
52# Tagging a commit causes a new commit to be created. (See https://repo.mercurial-scm.org/hg/help/revsets)
53exec hg update '.~1'
54cd a
55go install
56go version -m $GOBIN/a$GOEXE
57stdout '^\tbuild\tvcs.revision=71eaed52daeaafea83cb604f75b0a0336ef2c345$'
58stdout '^\tbuild\tvcs.time=2024-07-31T01:21:27Z$'
59stdout '^\tbuild\tvcs.modified=false$'
60stdout '\s+mod\s+example.com/a\s+v1.2.3\s+'
61rm $GOBIN/a$GOEXE
62
63# Add an extra commit and then back off of it to show that the hash is
64# from the checked out revision, not the tip revision.
65cp ../../outside/empty.txt .
66exec hg ci -Am 'another commit' --user test-user --date '2024-08-01T19:24:38+00:00'
67exec hg update --clean -r '.^'
68
69# Modified state is not thrown off by extra status output
70exec hg bisect -v -g .
71exec hg bisect -v -b '.^^'
72exec hg status
73stdout '^.+'
74go install
75go version -m $GOBIN/a$GOEXE
76stdout '^\tbuild\tvcs.revision=71eaed52daeaafea83cb604f75b0a0336ef2c345$'
77stdout '^\tbuild\tvcs.time=2024-07-31T01:21:27Z$'
78stdout '^\tbuild\tvcs.modified=false$'
79stdout '\s+mod\s+example.com/a\s+v1.2.3\s+'
80rm $GOBIN/a$GOEXE
81
82# Building with -buildvcs=false suppresses the info.
83go install -buildvcs=false
84go version -m $GOBIN/a$GOEXE
85! stdout hgrevision
86stdout '\s+mod\s+example.com/a\s+\(devel\)'
87rm $GOBIN/a$GOEXE
88
89# An untracked file is shown as uncommitted, even if it isn't part of the build.
90cp ../../outside/empty.txt .
91go install
92go version -m $GOBIN/a$GOEXE
93stdout '^\tbuild\tvcs.modified=true$'
94stdout '\s+mod\s+example.com/a\s+v1.2.3\+dirty\s+'
95rm empty.txt
96rm $GOBIN/a$GOEXE
97
98# An edited file is shown as uncommitted, even if it isn't part of the build.
99cp ../../outside/empty.txt ../README
100go install
101go version -m $GOBIN/a$GOEXE
102stdout '^\tbuild\tvcs.modified=true$'
103stdout '\s+mod\s+example.com/a\s+v1.2.3\+dirty\s+'
104exec hg revert ../README
105rm $GOBIN/a$GOEXE
106
107-- $WORK/fakebin/hg --
108#!/bin/sh
109exit 1
110-- $WORK/fakebin/hg.bat --
111exit 1
112-- repo/README --
113Far out in the uncharted backwaters of the unfashionable end of the western
114spiral arm of the Galaxy lies a small, unregarded yellow sun.
115-- repo/a/go.mod --
116module example.com/a
117
118go 1.18
119-- repo/a/a.go --
120package main
121
122func main() {}
123-- $WORK/hgrc --
124[ui]
125# tweakdefaults is an opt-in that may print extra output in commands like
126# status. That can be disabled by setting HGPLAIN=1.
127tweakdefaults = 1
128
129-- outside/empty.txt --
View as plain text