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

     1  # This test checks that VCS information is stamped into Go binaries by default,
     2  # controlled with -buildvcs. This test focuses on Mercurial specifics.
     3  # The Git test covers common functionality.
     4  
     5  [!exec:hg] skip
     6  [short] skip
     7  env GOBIN=$WORK/gopath/bin
     8  env oldpath=$PATH
     9  cd repo/a
    10  
    11  # If there's no local repository, there's no VCS info.
    12  go install
    13  go version -m $GOBIN/a$GOEXE
    14  ! stdout hgrevision
    15  rm $GOBIN/a$GOEXE
    16  
    17  # If there is a repository, but it can't be used for some reason,
    18  # there should be an error. It should hint about -buildvcs=false.
    19  cd ..
    20  mkdir .hg
    21  env PATH=$WORK${/}fakebin${:}$oldpath
    22  chmod 0755 $WORK/fakebin/hg
    23  ! exec hg help
    24  cd a
    25  ! go install
    26  stderr '^error obtaining VCS status: exit status 1\n\tUse -buildvcs=false to disable VCS stamping.$'
    27  rm $GOBIN/a$GOEXE
    28  cd ..
    29  env PATH=$oldpath
    30  rm .hg
    31  
    32  # If there is an empty repository in a parent directory, only "uncommitted" is tagged.
    33  exec hg init
    34  cd a
    35  go install
    36  go version -m $GOBIN/a$GOEXE
    37  ! stdout vcs.revision
    38  ! stdout vcs.time
    39  stdout '^\tbuild\tvcs.modified=true$'
    40  cd ..
    41  
    42  # Revision and commit time are tagged for repositories with commits.
    43  exec hg add a README
    44  exec hg commit -m 'initial commit'
    45  cd a
    46  go install
    47  go version -m $GOBIN/a$GOEXE
    48  stdout '^\tbuild\tvcs.revision='
    49  stdout '^\tbuild\tvcs.time='
    50  stdout '^\tbuild\tvcs.modified=false$'
    51  rm $GOBIN/a$GOEXE
    52  
    53  # Building with -buildvcs=false suppresses the info.
    54  go install -buildvcs=false
    55  go version -m $GOBIN/a$GOEXE
    56  ! stdout hgrevision
    57  rm $GOBIN/a$GOEXE
    58  
    59  # An untracked file is shown as uncommitted, even if it isn't part of the build.
    60  cp ../../outside/empty.txt .
    61  go install
    62  go version -m $GOBIN/a$GOEXE
    63  stdout '^\tbuild\tvcs.modified=true$'
    64  rm empty.txt
    65  rm $GOBIN/a$GOEXE
    66  
    67  # An edited file is shown as uncommitted, even if it isn't part of the build.
    68  cp ../../outside/empty.txt ../README
    69  go install
    70  go version -m $GOBIN/a$GOEXE
    71  stdout '^\tbuild\tvcs.modified=true$'
    72  exec hg revert ../README
    73  rm $GOBIN/a$GOEXE
    74  
    75  -- $WORK/fakebin/hg --
    76  #!/bin/sh
    77  exit 1
    78  -- $WORK/fakebin/hg.bat --
    79  exit 1
    80  -- repo/README --
    81  Far out in the uncharted backwaters of the unfashionable end of the western
    82  spiral arm of the Galaxy lies a small, unregarded yellow sun.
    83  -- repo/a/go.mod --
    84  module example.com/a
    85  
    86  go 1.18
    87  -- repo/a/a.go --
    88  package main
    89  
    90  func main() {}
    91  -- outside/empty.txt --
    92  

View as plain text