[short] skip
[!exec:hg] skip

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

# go mod download vcstest/tagtests@v0.2.2 should print origin info, no TagSum or RepoSum needed.
go mod download -x -json vcs-test.golang.org/hg/tagtests.hg@v0.2.2
cp stdout tagtestsv022.json
stdout '"Version": "v0.2.2"'
! stdout '"Query":'
stdout '"VCS": "hg"'
stdout '"URL": ".*/hg/tagtests"'
! stdout '"TagPrefix"'
! stdout '"TagSum"'
! stdout '"RepoSum"'
stdout '"Ref": "v0.2.2"'
stdout '"Hash": "1e531550e864b16f25013cfbbf2d8e7cf07a0374"'

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

# reuse attempt with stale hash should reinvoke hg, not report reuse
go clean -modcache
cp tagtestsv022.json tagtestsv022badhash.json
replace '1e5315' '1e5315XXX' tagtestsv022badhash.json
go mod download -reuse=tagtestsv022badhash.json -x -json vcs-test.golang.org/hg/tagtests.hg@v0.2.2
stderr 'hg( .*)* pull'
! stdout '"Reuse": true'
stdout '"Version": "v0.2.2"'
! stdout '"Query"'
stdout '"VCS": "hg"'
stdout '"URL": ".*/hg/tagtests"'
! stdout '"(TagPrefix|TagSum|RepoSum)"'
stdout '"Ref": "v0.2.2"'
stdout '"Hash": "1e531550e864b16f25013cfbbf2d8e7cf07a0374"'
stdout '"Dir"'
stdout '"Info"'
stdout '"GoMod"'
stdout '"Zip"'

# reuse with stale repo URL
go clean -modcache
cp tagtestsv022.json tagtestsv022badurl.json
replace 'hg/tagtests\"' 'hg/tagtestsXXX\"' tagtestsv022badurl.json
go mod download -reuse=tagtestsv022badurl.json -x -json vcs-test.golang.org/hg/tagtests.hg@v0.2.2
! stdout '"Reuse": true'
stdout '"URL": ".*/hg/tagtests"'
stdout '"Dir"'
stdout '"Info"'
stdout '"GoMod"'
stdout '"Zip"'

# reuse with stale VCS
go clean -modcache
cp tagtestsv022.json tagtestsv022badvcs.json
replace '\"hg\"' '\"hgXXX\"' tagtestsv022badvcs.json
go mod download -reuse=tagtestsv022badvcs.json -x -json vcs-test.golang.org/hg/tagtests.hg@v0.2.2
! stdout '"Reuse": true'
stdout '"URL": ".*/hg/tagtests"'
! stdout '"RepoSum"'

# reuse with stale Dir
go clean -modcache
cp tagtestsv022.json tagtestsv022baddir.json
replace '\"VCS\":' '\"Subdir\":\"subdir\", \"VCS\":' tagtestsv022baddir.json
go mod download -reuse=tagtestsv022baddir.json -x -json vcs-test.golang.org/hg/tagtests.hg@v0.2.2
! stdout '"Reuse": true'
stdout '"URL": ".*/hg/tagtests"'
! stdout '"RepoSum"'