[short] skip
[!exec:hg] skip

env GO111MODULE=on
env GOPROXY=direct
env GOSUMDB=off
env GOMODCACHE=$WORK/modcache

# go mod download with the pseudo-version should invoke hg but not have a TagSum or Ref or RepoSum.
go mod download -x -json vcs-test.golang.org/hg/hello.hg@v0.0.0-20170922011414-e483a7d9f8c9
stderr 'hg( .*)* pull'
cp stdout hellopseudo.json
! stdout '"(Query|TagPrefix|TagSum|Ref|RepoSum)"'
stdout '"Version": "v0.0.0-20170922011414-e483a7d9f8c9"'
stdout '"VCS": "hg"'
stdout '"URL": ".*/hg/hello"'
stdout '"Hash": "e483a7d9f8c9b4bc57430bdd8f81f0a65e4011c0"'
! stdout '"RepoSum"'
go clean -modcache


# go mod download vcstest/hello should invoke hg, print origin info
go mod download -x -json vcs-test.golang.org/hg/hello.hg@latest
stderr 'hg( .*)* pull'
cp stdout hello.json
stdout '"Version": "v0.0.0-20170922011414-e483a7d9f8c9"'
stdout '"VCS": "hg"'
stdout '"URL": ".*/hg/hello"'
stdout '"Query": "latest"'
! stdout '"TagPrefix"'
! stdout '"TagSum"'
stdout '"Ref": "tip"'
stdout '"RepoSum": "r1:blLvkhBriVMV[+]6Il4Ub43wlyWXIe1NpobTelF0peaG0="'
stdout '"Hash": "e483a7d9f8c9b4bc57430bdd8f81f0a65e4011c0"'

# pseudo-version again should not invoke hg pull (it has the version from the @latest query)
# but still be careful not to include a TagSum or a Ref, especially not Ref set to HEAD,
# which is easy to do when reusing the cached version from the @latest query.
go mod download -x -json vcs-test.golang.org/hg/hello.hg@v0.0.0-20170922011414-e483a7d9f8c9
! stderr 'hg( .*)* pull'
cp stdout hellopseudo2.json
cmpenv hellopseudo.json hellopseudo2.json

# reuse go mod download vcstest/hello pseudoversion result
go clean -modcache
go mod download -reuse=hellopseudo.json -x -json vcs-test.golang.org/hg/hello.hg@v0.0.0-20170922011414-e483a7d9f8c9
! stderr 'hg( .*)* pull'
stdout '"Reuse": true'
stdout '"Version": "v0.0.0-20170922011414-e483a7d9f8c9"'
stdout '"VCS": "hg"'
stdout '"URL": ".*/hg/hello"'
! stdout '"(Query|TagPrefix|TagSum|Ref)"'
stdout '"Hash": "e483a7d9f8c9b4bc57430bdd8f81f0a65e4011c0"'
! stdout '"(Dir|Info|GoMod|Zip|RepoSum)"'

# reuse go mod download vcstest/hello result
go clean -modcache
go mod download -reuse=hello.json -x -json vcs-test.golang.org/hg/hello.hg@latest
! stderr 'hg( .*)* pull'
stdout '"Reuse": true'
stdout '"Version": "v0.0.0-20170922011414-e483a7d9f8c9"'
stdout '"VCS": "hg"'
stdout '"URL": ".*/hg/hello"'
! stdout '"TagPrefix"'
stdout '"RepoSum": "r1:blLvkhBriVMV[+]6Il4Ub43wlyWXIe1NpobTelF0peaG0="'
stdout '"Ref": "tip"'
stdout '"Hash": "e483a7d9f8c9b4bc57430bdd8f81f0a65e4011c0"'
! stdout '"(Dir|Info|GoMod|Zip)"'

# clean the module cache, make sure that makes go mod download re-run hg pull, clean again
go clean -modcache
go mod download -x -json vcs-test.golang.org/hg/hello.hg@latest
stderr 'hg( .*)* pull'
go clean -modcache