...

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

Documentation: cmd/go/testdata/script

     1# Test that 'go build' stamps VCS information when building from a git worktree.
     2# See https://go.dev/issue/58218.
     3
     4[!git] skip
     5[short] skip
     6
     7# Create repo with a commit.
     8cd repo
     9exec git init
    10exec git config user.email g.o.p.h.e.r@go.dev
    11exec git config user.name Gopher
    12exec git add -A
    13exec git commit -m 'initial commit'
    14
    15# Sanity check: building from main repo includes VCS info.
    16go build -o main.exe .
    17go version -m main.exe
    18stdout '^\tbuild\tvcs=git$'
    19stdout '^\tbuild\tvcs.modified=false$'
    20
    21# Create a worktree and build from it.
    22exec git worktree add ../worktree HEAD
    23cd ../worktree
    24go build -o worktree.exe .
    25go version -m worktree.exe
    26stdout '^\tbuild\tvcs=git$'
    27stdout '^\tbuild\tvcs.modified=false$'
    28
    29# Verify that vcs.modified is detected in the worktree.
    30cp ../changed.go a.go
    31go build -o modified.exe .
    32go version -m modified.exe
    33stdout '^\tbuild\tvcs.modified=true$'
    34
    35-- repo/go.mod --
    36module example.com/worktree
    37
    38go 1.18
    39-- repo/a.go --
    40package main
    41
    42func main() {}
    43-- changed.go --
    44package main
    45
    46func main() { _ = 1 }

View as plain text