...

Text file src/cmd/go/testdata/script/version_buildvcs_nested.txt

Documentation: cmd/go/testdata/script

     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
    13# Nesting repositories in parent directories are an error, to prevent VCS injection.
    14# This can be disabled with the allowmultiplevcs GODEBUG.
    15mkdir hgsub
    16cd hgsub
    17exec hg init
    18cp ../../main.go main.go
    19! go build
    20stderr '^error obtaining VCS status: multiple VCS detected: hg in ".*hgsub", and git in ".*root"$'
    21stderr '^\tUse -buildvcs=false to disable VCS stamping.$'
    22env GODEBUG=allowmultiplevcs=1
    23! go build
    24stderr '^error obtaining VCS status: main module is in repository ".*root" but current directory is in repository ".*hgsub"$'
    25stderr '^\tUse -buildvcs=false to disable VCS stamping.$'
    26go build -buildvcs=false
    27env GODEBUG=
    28go mod init example.com/root/hgsub
    29! go build
    30stderr '^error obtaining VCS status: multiple VCS detected: hg in ".*hgsub", and git in ".*root"$'
    31stderr '^\tUse -buildvcs=false to disable VCS stamping.$'
    32env GODEBUG=allowmultiplevcs=1
    33go build
    34env GODEBUG=
    35cd ..
    36
    37# It's an error to build a package from a nested Git repository if the package
    38# is in a separate repository from the current directory or from the module
    39# root directory. Otherwise nested Git repositories are allowed, as this is
    40# how Git implements submodules (and protects against Git based VCS injection.)
    41mkdir gitsub
    42cd gitsub
    43exec git init
    44exec git config user.name 'J.R.Gopher'
    45exec git config user.email 'gopher@golang.org'
    46cp ../../main.go main.go
    47! go build
    48stderr '^error obtaining VCS status: main module is in repository ".*root" but current directory is in repository ".*gitsub"$'
    49go build -buildvcs=false
    50go mod init example.com/root/gitsub
    51exec git commit --allow-empty -m empty # status commands fail without this
    52go build
    53rm go.mod
    54cd ..
    55! go build ./gitsub
    56stderr '^error obtaining VCS status: main package is in repository ".*gitsub" but current directory is in repository ".*root"$'
    57go build -buildvcs=false -o=gitsub${/} ./gitsub
    58
    59-- main.go --
    60package main
    61func main() {}

View as plain text