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

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

View as plain text