...
1[!git] skip
2[!exec:hg] skip
3[short] skip
4env GOFLAGS='-n -buildvcs'
5
6# Create a root module in a root Git repository.
7mkdir root
8cd root
9go mod init example.com/root
10exec 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.
16mkdir hgsub
17cd hgsub
18exec hg init
19cp ../../main.go main.go
20! go build
21stderr '^error obtaining VCS status: main module is in repository ".*root" but current directory is in repository ".*hgsub"$'
22stderr '^\tUse -buildvcs=false to disable VCS stamping.$'
23go build -buildvcs=false
24go mod init example.com/root/hgsub
25go build
26cd ..
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.
31mkdir gitsub
32cd gitsub
33exec git init
34exec git config user.name 'J.R.Gopher'
35exec git config user.email 'gopher@golang.org'
36cp ../../main.go main.go
37! go build
38stderr '^error obtaining VCS status: main module is in repository ".*root" but current directory is in repository ".*gitsub"$'
39go build -buildvcs=false
40go mod init example.com/root/gitsub
41exec git commit --allow-empty -m empty # status commands fail without this
42go build
43rm go.mod
44cd ..
45! go build ./gitsub
46stderr '^error obtaining VCS status: main package is in repository ".*gitsub" but current directory is in repository ".*root"$'
47go build -buildvcs=false -o=gitsub${/} ./gitsub
48
49-- main.go --
50package main
51func main() {}
View as plain text