blob: 78ce2e835ec9c1e647f5d1dfe43c65df2caf02a9 [file] [log] [blame]
# This test checks that VCS information is stamped into Go binaries by default,
# controlled with -buildvcs. This test focuses on Git. Other tests focus on
# other VCS tools but may not cover common functionality.
[!exec:git] skip
[short] skip
env GOBIN=$WORK/gopath/bin
env oldpath=$PATH
cd repo/a
# If there's no local repository, there's no VCS info.
go install
go version -m $GOBIN/a$GOEXE
! stdout gitrevision
rm $GOBIN/a$GOEXE
# If there is a repository, but it can't be used for some reason,
# there should be an error. It should hint about -buildvcs=false.
cd ..
mkdir .git
env PATH=$WORK${/}fakebin${:}$oldpath
chmod 0755 $WORK/fakebin/git
! exec git help
cd a
! go install
stderr '^error obtaining VCS status: exit status 1\n\tUse -buildvcs=false to disable VCS stamping.$'
cd ..
env PATH=$oldpath
rm .git
# If there is a repository in a parent directory, there should be VCS info.
exec git init
exec git config user.email gopher@golang.org
exec git config user.name 'J.R. Gopher'
exec git add -A
exec git commit -m 'initial commit'
cd a
go install
go version -m $GOBIN/a$GOEXE
stdout '^\tbuild\tgitrevision\t'
stdout '^\tbuild\tgituncommitted\tfalse$'
rm $GOBIN/a$GOEXE
# Building with -buildvcs=false suppresses the info.
go install -buildvcs=false
go version -m $GOBIN/a$GOEXE
! stdout gitrevision
rm $GOBIN/a$GOEXE
# An untracked file is shown as uncommitted, even if it isn't part of the build.
cp ../../outside/empty.txt .
go install
go version -m $GOBIN/a$GOEXE
stdout '^\tbuild\tgituncommitted\ttrue$'
rm empty.txt
rm $GOBIN/a$GOEXE
# An edited file is shown as uncommitted, even if it isn't part of the build.
cp ../../outside/empty.txt ../README
go install
go version -m $GOBIN/a$GOEXE
stdout '^\tbuild\tgituncommitted\ttrue$'
exec git checkout ../README
rm $GOBIN/a$GOEXE
# If the build doesn't include any packages from the repository,
# there should be no VCS info.
go install example.com/cmd/a@v1.0.0
go version -m $GOBIN/a$GOEXE
! stdout gitrevision
rm $GOBIN/a$GOEXE
go mod edit -require=example.com/c@v0.0.0
go mod edit -replace=example.com/c@v0.0.0=../../outside/c
go install example.com/c
go version -m $GOBIN/c$GOEXE
! stdout gitrevision
rm $GOBIN/c$GOEXE
exec git checkout go.mod
# If the build depends on a package in the repository, but it's not in the
# main module, there should be no VCS info.
go mod edit -require=example.com/b@v0.0.0
go mod edit -replace=example.com/b@v0.0.0=../b
go mod edit -require=example.com/d@v0.0.0
go mod edit -replace=example.com/d@v0.0.0=../../outside/d
go install example.com/d
go version -m $GOBIN/d$GOEXE
! stdout gitrevision
exec git checkout go.mod
rm $GOBIN/d$GOEXE
-- $WORK/fakebin/git --
#!/bin/sh
exit 1
-- $WORK/fakebin/git.bat --
exit 1
-- repo/README --
Far out in the uncharted backwaters of the unfashionable end of the western
spiral arm of the Galaxy lies a small, unregarded yellow sun.
-- repo/a/go.mod --
module example.com/a
go 1.18
-- repo/a/a.go --
package main
func main() {}
-- repo/b/go.mod --
module example.com/b
go 1.18
-- repo/b/b.go --
package b
-- outside/empty.txt --
-- outside/c/go.mod --
module example.com/c
go 1.18
-- outside/c/main.go --
package main
func main() {}
-- outside/d/go.mod --
module example.com/d
go 1.18
require example.com/b v0.0.0
-- outside/d/main.go --
package main
import _ "example.com/b"
func main() {}