...
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
9cd repo/a
10
11# If there's no local repository, there's no VCS info.
12go install
13go version -m $GOBIN/a$GOEXE
14! stdout hgrevision
15rm $GOBIN/a$GOEXE
16
17# If there is a repository, but it can't be used for some reason,
18# there should be an error. It should hint about -buildvcs=false.
19cd ..
20mkdir .hg
21env PATH=$WORK${/}fakebin${:}$oldpath
22chmod 0755 $WORK/fakebin/hg
23! exec hg help
24cd a
25! go install
26stderr '^error obtaining VCS status: exit status 1\n\tUse -buildvcs=false to disable VCS stamping.$'
27rm $GOBIN/a$GOEXE
28cd ..
29env PATH=$oldpath
30rm .hg
31
32# If there is an empty repository in a parent directory, only "uncommitted" is tagged.
33exec hg init
34cd a
35go install
36go version -m $GOBIN/a$GOEXE
37! stdout vcs.revision
38! stdout vcs.time
39stdout '^\tbuild\tvcs.modified=true$'
40cd ..
41
42# Revision and commit time are tagged for repositories with commits.
43exec hg add a README
44exec hg commit -m 'initial commit'
45cd a
46go install
47go version -m $GOBIN/a$GOEXE
48stdout '^\tbuild\tvcs.revision='
49stdout '^\tbuild\tvcs.time='
50stdout '^\tbuild\tvcs.modified=false$'
51rm $GOBIN/a$GOEXE
52
53# Building with -buildvcs=false suppresses the info.
54go install -buildvcs=false
55go version -m $GOBIN/a$GOEXE
56! stdout hgrevision
57rm $GOBIN/a$GOEXE
58
59# An untracked file is shown as uncommitted, even if it isn't part of the build.
60cp ../../outside/empty.txt .
61go install
62go version -m $GOBIN/a$GOEXE
63stdout '^\tbuild\tvcs.modified=true$'
64rm empty.txt
65rm $GOBIN/a$GOEXE
66
67# An edited file is shown as uncommitted, even if it isn't part of the build.
68cp ../../outside/empty.txt ../README
69go install
70go version -m $GOBIN/a$GOEXE
71stdout '^\tbuild\tvcs.modified=true$'
72exec hg revert ../README
73rm $GOBIN/a$GOEXE
74
75-- $WORK/fakebin/hg --
76#!/bin/sh
77exit 1
78-- $WORK/fakebin/hg.bat --
79exit 1
80-- repo/README --
81Far out in the uncharted backwaters of the unfashionable end of the western
82spiral arm of the Galaxy lies a small, unregarded yellow sun.
83-- repo/a/go.mod --
84module example.com/a
85
86go 1.18
87-- repo/a/a.go --
88package main
89
90func main() {}
91-- outside/empty.txt --
View as plain text