1 [!exec:git] skip
2 [!exec:hg] skip
3 [short] skip
4 env GOFLAGS='-n -buildvcs'
5
6 # Create a root module in a root Git repository.
7 mkdir root
8 cd root
9 go mod init example.com/root
10 exec git init
11
12 # Nesting repositories in parent directories are ignored, as the current
13 # directory main package, and containing main module are in the same repository.
14 # This is an error in GOPATH mode (to prevent VCS injection), but for modules,
15 # we assume users have control over repositories they've checked out.
16 mkdir hgsub
17 cd hgsub
18 exec hg init
19 cp ../../main.go main.go
20 ! go build
21 stderr '^error obtaining VCS status: main module is in repository ".*root" but current directory is in repository ".*hgsub"$'
22 stderr '^\tUse -buildvcs=false to disable VCS stamping.$'
23 go build -buildvcs=false
24 go mod init example.com/root/hgsub
25 go build
26 cd ..
27
28 # It's an error to build a package from a nested Git repository if the package
29 # is in a separate repository from the current directory or from the module
30 # root directory.
31 mkdir gitsub
32 cd gitsub
33 exec git init
34 exec git config user.name 'J.R.Gopher'
35 exec git config user.email 'gopher@golang.org'
36 cp ../../main.go main.go
37 ! go build
38 stderr '^error obtaining VCS status: main module is in repository ".*root" but current directory is in repository ".*gitsub"$'
39 go build -buildvcs=false
40 go mod init example.com/root/gitsub
41 exec git commit --allow-empty -m empty # status commands fail without this
42 go build
43 rm go.mod
44 cd ..
45 ! go build ./gitsub
46 stderr '^error obtaining VCS status: main package is in repository ".*gitsub" but current directory is in repository ".*root"$'
47 go build -buildvcs=false -o=gitsub${/} ./gitsub
48
49 -- main.go --
50 package main
51 func main() {}
52
View as plain text