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

     1  # Regression test for https://go.dev/issue/51748: by default, 'go build' should
     2  # not attempt to stamp VCS information when the VCS tool is not present.
     3  
     4  [short] skip
     5  [!git] skip
     6  
     7  cd sub
     8  exec git init .
     9  exec git config user.name 'Nameless Gopher'
    10  exec git config user.email 'nobody@golang.org'
    11  exec git add sub.go
    12  exec git commit -m 'initial state'
    13  cd ..
    14  
    15  exec git init
    16  exec git config user.name 'Nameless Gopher'
    17  exec git config user.email 'nobody@golang.org'
    18  exec git submodule add ./sub
    19  exec git add go.mod example.go
    20  exec git commit -m 'initial state'
    21  
    22  
    23  # Control case: with a git binary in $PATH,
    24  # 'go build' on a package in the same git repo
    25  # succeeds and stamps VCS metadata by default.
    26  
    27  go build -o example.exe .
    28  go version -m example.exe
    29  stdout '^\tbuild\tvcs=git$'
    30  stdout '^\tbuild\tvcs.modified=false$'
    31  
    32  
    33  # Building a binary from a different (nested) VCS repo should not stamp VCS
    34  # info. It should be an error if VCS stamps are requested explicitly with
    35  # '-buildvcs' (since we know the VCS metadata exists), but not an error
    36  # with '-buildvcs=auto'.
    37  
    38  go build -o sub.exe ./sub
    39  go version -m sub.exe
    40  ! stdout '^\tbuild\tvcs'
    41  
    42  ! go build -buildvcs -o sub.exe ./sub
    43  stderr '\Aerror obtaining VCS status: main package is in repository ".*" but current directory is in repository ".*"\n\tUse -buildvcs=false to disable VCS stamping.\n\z'
    44  
    45  cd ./sub
    46  go build -o sub.exe .
    47  go version -m sub.exe
    48  ! stdout '^\tbuild\tvcs'
    49  
    50  ! go build -buildvcs -o sub.exe .
    51  stderr '\Aerror obtaining VCS status: main module is in repository ".*" but current directory is in repository ".*"\n\tUse -buildvcs=false to disable VCS stamping.\n\z'
    52  cd ..
    53  
    54  
    55  # After removing 'git' from $PATH, 'go build -buildvcs' should fail...
    56  
    57  env PATH=
    58  env path=
    59  ! go build -buildvcs -o example.exe .
    60  stderr 'go: missing Git command\. See https://golang\.org/s/gogetcmd$'
    61  
    62  # ...but by default we should omit VCS metadata when the tool is missing.
    63  
    64  go build -o example.exe .
    65  go version -m example.exe
    66  ! stdout '^\tbuild\tvcs'
    67  
    68  # The default behavior can be explicitly set with '-buildvcs=auto'.
    69  
    70  go build -buildvcs=auto -o example.exe .
    71  go version -m example.exe
    72  ! stdout '^\tbuild\tvcs'
    73  
    74  # Other flag values should be rejected with a useful error message.
    75  
    76  ! go build -buildvcs=hg -o example.exe .
    77  stderr '\Ainvalid boolean value "hg" for -buildvcs: value is neither ''auto'' nor a valid bool\nusage: go build .*\nRun ''go help build'' for details.\n\z'
    78  
    79  
    80  -- go.mod --
    81  module example
    82  
    83  go 1.18
    84  -- example.go --
    85  package main
    86  
    87  func main() {}
    88  -- sub/sub.go --
    89  package main
    90  
    91  func main() {}
    92  

View as plain text