...

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

Documentation: cmd/go/testdata/script

     1[short] skip
     2[!git] skip
     3
     4env GO111MODULE=on
     5env GOPROXY=direct
     6env GOSUMDB=off
     7
     8# go mod download with the pseudo-version should invoke git but not have a TagSum or Ref.
     9go mod download -x -json vcs-test.golang.org/git/hello.git@v0.0.0-20170922010558-fc3a09f3dc5c
    10stderr 'git( .*)* fetch'
    11cp stdout hellopseudo.json
    12! stdout '"(Query|TagPrefix|TagSum|Ref)"'
    13stdout '"Version": "v0.0.0-20170922010558-fc3a09f3dc5c"'
    14stdout '"VCS": "git"'
    15stdout '"URL": ".*/git/hello"'
    16stdout '"Hash": "fc3a09f3dc5cfe0d7a743ea18f1f5226e68b3777"'
    17go clean -modcache
    18
    19# go mod download vcstest/hello should invoke git, print origin info
    20go mod download -x -json vcs-test.golang.org/git/hello.git@latest
    21stderr 'git( .*)* fetch'
    22cp stdout hello.json
    23stdout '"Version": "v0.0.0-20170922010558-fc3a09f3dc5c"'
    24stdout '"VCS": "git"'
    25stdout '"URL": ".*/git/hello"'
    26stdout '"Query": "latest"'
    27! stdout '"TagPrefix"'
    28stdout '"TagSum": "t1:47DEQpj8HBSa[+]/TImW[+]5JCeuQeRkm5NMpJWZG3hSuFU="'
    29stdout '"Ref": "HEAD"'
    30stdout '"Hash": "fc3a09f3dc5cfe0d7a743ea18f1f5226e68b3777"'
    31
    32# pseudo-version again should not invoke git fetch (it has the version from the @latest query)
    33# but still be careful not to include a TagSum or a Ref, especially not Ref set to HEAD,
    34# which is easy to do when reusing the cached version from the @latest query.
    35go mod download -x -json vcs-test.golang.org/git/hello.git@v0.0.0-20170922010558-fc3a09f3dc5c
    36! stderr 'git( .*)* fetch'
    37cp stdout hellopseudo2.json
    38cmpenv hellopseudo.json hellopseudo2.json
    39
    40# go mod download vcstest/hello@hash needs to check TagSum to find pseudoversion base.
    41go mod download -x -json vcs-test.golang.org/git/hello.git@fc3a09f3dc5c
    42! stderr 'git( .*)* fetch'
    43cp stdout hellohash.json
    44stdout '"Version": "v0.0.0-20170922010558-fc3a09f3dc5c"'
    45stdout '"Query": "fc3a09f3dc5c"'
    46stdout '"VCS": "git"'
    47stdout '"URL": ".*/git/hello"'
    48stdout '"TagSum": "t1:47DEQpj8HBSa[+]/TImW[+]5JCeuQeRkm5NMpJWZG3hSuFU="'
    49stdout '"Hash": "fc3a09f3dc5cfe0d7a743ea18f1f5226e68b3777"'
    50
    51# go mod download vcstest/hello/v9 should fail, still print origin info
    52! go mod download -x -json vcs-test.golang.org/git/hello.git/v9@latest
    53cp stdout hellov9.json
    54stdout '"Version": "latest"'
    55stdout '"Error":.*no matching versions'
    56! stdout '"TagPrefix"'
    57stdout '"TagSum": "t1:47DEQpj8HBSa[+]/TImW[+]5JCeuQeRkm5NMpJWZG3hSuFU="'
    58stdout '"Ref": "HEAD"'
    59stdout '"Hash": "fc3a09f3dc5cfe0d7a743ea18f1f5226e68b3777"'
    60! stdout 'RepoSum'
    61
    62# go mod download vcstest/hello/sub/v9 should also fail, print origin info with TagPrefix
    63! go mod download -x -json vcs-test.golang.org/git/hello.git/sub/v9@latest
    64cp stdout hellosubv9.json
    65stdout '"Version": "latest"'
    66stdout '"Error":.*no matching versions'
    67stdout '"TagPrefix": "sub/"'
    68stdout '"TagSum": "t1:47DEQpj8HBSa[+]/TImW[+]5JCeuQeRkm5NMpJWZG3hSuFU="'
    69stdout '"Ref": "HEAD"'
    70stdout '"Hash": "fc3a09f3dc5cfe0d7a743ea18f1f5226e68b3777"'
    71! stdout 'RepoSum'
    72
    73# go mod download vcstest/hello@nonexist should fail, still print origin info
    74! go mod download -x -json vcs-test.golang.org/git/hello.git@nonexist
    75cp stdout hellononexist.json
    76stdout '"Version": "nonexist"'
    77stdout '"Error":.*unknown revision nonexist'
    78stdout '"RepoSum": "r1:c0/9JCZ25lxoBiK3[+]3BhACU4giH49flcJmBynJ[+]Jvmc="'
    79! stdout '"(TagPrefix|TagSum|Ref|Hash)"'
    80
    81# go mod download vcstest/hello@1234567890123456789012345678901234567890 should fail, still print origin info
    82# (40 hex digits is assumed to be a full hash and is a slightly different code path from @nonexist)
    83! go mod download -x -json vcs-test.golang.org/git/hello.git@1234567890123456789012345678901234567890
    84cp stdout hellononhash.json
    85stdout '"Version": "1234567890123456789012345678901234567890"'
    86stdout '"Error":.*unknown revision 1234567890123456789012345678901234567890'
    87stdout '"RepoSum": "r1:c0/9JCZ25lxoBiK3[+]3BhACU4giH49flcJmBynJ[+]Jvmc="'
    88! stdout '"(TagPrefix|TagSum|Ref|Hash)"'
    89
    90# go mod download vcstest/hello@v0.0.0-20220101120101-123456789abc should fail, still print origin info
    91# (non-existent pseudoversion)
    92! go mod download -x -json vcs-test.golang.org/git/hello.git@v0.0.0-20220101120101-123456789abc
    93cp stdout hellononpseudo.json
    94stdout '"Version": "v0.0.0-20220101120101-123456789abc"'
    95stdout '"Error":.*unknown revision 123456789abc'
    96stdout '"RepoSum": "r1:c0/9JCZ25lxoBiK3[+]3BhACU4giH49flcJmBynJ[+]Jvmc="'
    97! stdout '"(TagPrefix|TagSum|Ref|Hash)"'
    98
    99# go mod download vcstest/tagtests should invoke git, print origin info
   100go mod download -x -json vcs-test.golang.org/git/tagtests.git@latest
   101stderr 'git( .*)* fetch'
   102cp stdout tagtests.json
   103stdout '"Version": "v0.2.2"'
   104stdout '"Query": "latest"'
   105stdout '"VCS": "git"'
   106stdout '"URL": ".*/git/tagtests"'
   107! stdout '"TagPrefix"'
   108stdout '"TagSum": "t1:Dp7yRKDuE8WjG0429PN9hYWjqhy2te7P9Oki/sMEOGo="'
   109stdout '"Ref": "refs/tags/v0.2.2"'
   110stdout '"Hash": "59356c8cd18c5fe9a598167d98a6843e52d57952"'
   111
   112# go mod download vcstest/tagtests@v0.2.2 should print origin info, no TagSum needed
   113go mod download -x -json vcs-test.golang.org/git/tagtests.git@v0.2.2
   114cp stdout tagtestsv022.json
   115stdout '"Version": "v0.2.2"'
   116! stdout '"Query":'
   117stdout '"VCS": "git"'
   118stdout '"URL": ".*/git/tagtests"'
   119! stdout '"TagPrefix"'
   120! stdout '"TagSum"'
   121stdout '"Ref": "refs/tags/v0.2.2"'
   122stdout '"Hash": "59356c8cd18c5fe9a598167d98a6843e52d57952"'
   123
   124# go mod download vcstest/tagtests@master needs a TagSum again
   125go mod download -x -json vcs-test.golang.org/git/tagtests.git@master
   126cp stdout tagtestsmaster.json
   127stdout '"Version": "v0.2.3-0.20190509225625-c7818c24fa2f"'
   128stdout '"Query": "master"'
   129stdout '"VCS": "git"'
   130stdout '"URL": ".*/git/tagtests"'
   131! stdout '"TagPrefix"'
   132stdout '"TagSum": "t1:Dp7yRKDuE8WjG0429PN9hYWjqhy2te7P9Oki/sMEOGo="'
   133stdout '"Ref": "refs/heads/master"'
   134stdout '"Hash": "c7818c24fa2f3f714c67d0a6d3e411c85a518d1f"'
   135
   136# go mod download vcstest/prefixtagtests should invoke git, print origin info
   137go mod download -x -json vcs-test.golang.org/git/prefixtagtests.git/sub@latest
   138stderr 'git( .*)* fetch'
   139cp stdout prefixtagtests.json
   140stdout '"Version": "v0.0.10"'
   141stdout '"Query": "latest"'
   142stdout '"VCS": "git"'
   143stdout '"URL": ".*/git/prefixtagtests"'
   144stdout '"Subdir": "sub"'
   145stdout '"TagPrefix": "sub/"'
   146stdout '"TagSum": "t1:YGSbWkJ8dn9ORAr[+]BlKHFK/2ZhXLb9hVuYfTZ9D8C7g="'
   147stdout '"Ref": "refs/tags/sub/v0.0.10"'
   148stdout '"Hash": "2b7c4692e12c109263cab51b416fcc835ddd7eae"'
   149
   150# go mod download of a bunch of these should fail (some are invalid) but write good JSON for later
   151! go mod download -json vcs-test.golang.org/git/hello.git@latest vcs-test.golang.org/git/hello.git/v9@latest vcs-test.golang.org/git/hello.git/sub/v9@latest vcs-test.golang.org/git/tagtests.git@latest vcs-test.golang.org/git/tagtests.git@v0.2.2 vcs-test.golang.org/git/tagtests.git@master
   152cp stdout all.json
   153
   154# clean the module cache, make sure that makes go mod download re-run git fetch, clean again
   155go clean -modcache
   156go mod download -x -json vcs-test.golang.org/git/hello.git@latest
   157stderr 'git( .*)* fetch'
   158go clean -modcache
   159
   160# reuse go mod download vcstest/hello result
   161go mod download -reuse=hello.json -x -json vcs-test.golang.org/git/hello.git@latest
   162! stderr 'git( .*)* fetch'
   163stdout '"Reuse": true'
   164stdout '"Version": "v0.0.0-20170922010558-fc3a09f3dc5c"'
   165stdout '"VCS": "git"'
   166stdout '"URL": ".*/git/hello"'
   167! stdout '"TagPrefix"'
   168stdout '"TagSum": "t1:47DEQpj8HBSa[+]/TImW[+]5JCeuQeRkm5NMpJWZG3hSuFU="'
   169stdout '"Ref": "HEAD"'
   170stdout '"Hash": "fc3a09f3dc5cfe0d7a743ea18f1f5226e68b3777"'
   171! stdout '"Dir"'
   172! stdout '"Info"'
   173! stdout '"GoMod"'
   174! stdout '"Zip"'
   175
   176# reuse go mod download vcstest/hello pseudoversion result
   177go mod download -reuse=hellopseudo.json -x -json vcs-test.golang.org/git/hello.git@v0.0.0-20170922010558-fc3a09f3dc5c
   178! stderr 'git( .*)* fetch'
   179stdout '"Reuse": true'
   180stdout '"Version": "v0.0.0-20170922010558-fc3a09f3dc5c"'
   181stdout '"VCS": "git"'
   182stdout '"URL": ".*/git/hello"'
   183! stdout '"(Query|TagPrefix|TagSum|Ref)"'
   184stdout '"Hash": "fc3a09f3dc5cfe0d7a743ea18f1f5226e68b3777"'
   185! stdout '"(Dir|Info|GoMod|Zip)"'
   186
   187# reuse go mod download vcstest/hello@hash
   188go mod download -reuse=hellohash.json -x -json vcs-test.golang.org/git/hello.git@fc3a09f3dc5c
   189! stderr 'git( .*)* fetch'
   190stdout '"Reuse": true'
   191stdout '"Query": "fc3a09f3dc5c"'
   192stdout '"Version": "v0.0.0-20170922010558-fc3a09f3dc5c"'
   193stdout '"VCS": "git"'
   194stdout '"URL": ".*/git/hello"'
   195! stdout '"(TagPrefix|Ref)"'
   196stdout '"TagSum": "t1:47DEQpj8HBSa[+]/TImW[+]5JCeuQeRkm5NMpJWZG3hSuFU="'
   197stdout '"Hash": "fc3a09f3dc5cfe0d7a743ea18f1f5226e68b3777"'
   198! stdout '"(Dir|Info|GoMod|Zip)"'
   199
   200# reuse go mod download vcstest/hello/v9 error result
   201! go mod download -reuse=hellov9.json -x -json vcs-test.golang.org/git/hello.git/v9@latest
   202! stderr 'git( .*)* fetch'
   203stdout '"Reuse": true'
   204stdout '"Error":.*no matching versions'
   205! stdout '"TagPrefix"'
   206stdout '"TagSum": "t1:47DEQpj8HBSa[+]/TImW[+]5JCeuQeRkm5NMpJWZG3hSuFU="'
   207stdout '"Ref": "HEAD"'
   208stdout '"Hash": "fc3a09f3dc5cfe0d7a743ea18f1f5226e68b3777"'
   209! stdout '"(Dir|Info|GoMod|Zip)"'
   210
   211# reuse go mod download vcstest/hello/sub/v9 error result
   212! go mod download -reuse=hellosubv9.json -x -json vcs-test.golang.org/git/hello.git/sub/v9@latest
   213! stderr 'git( .*)* fetch'
   214stdout '"Reuse": true'
   215stdout '"Error":.*no matching versions'
   216stdout '"TagPrefix": "sub/"'
   217stdout '"TagSum": "t1:47DEQpj8HBSa[+]/TImW[+]5JCeuQeRkm5NMpJWZG3hSuFU="'
   218stdout '"Ref": "HEAD"'
   219stdout '"Hash": "fc3a09f3dc5cfe0d7a743ea18f1f5226e68b3777"'
   220! stdout '"(Dir|Info|GoMod|Zip)"'
   221
   222# reuse go mod download vcstest/hello@nonexist
   223! go mod download -reuse=hellononexist.json -x -json vcs-test.golang.org/git/hello.git@nonexist
   224! stderr 'git( .*)* fetch'
   225stdout '"Reuse": true'
   226stdout '"Version": "nonexist"'
   227stdout '"Error":.*unknown revision nonexist'
   228stdout '"RepoSum": "r1:c0/9JCZ25lxoBiK3[+]3BhACU4giH49flcJmBynJ[+]Jvmc="'
   229! stdout '"(TagPrefix|TagSum|Ref|Hash)"'
   230! stdout '"(Dir|Info|GoMod|Zip)"'
   231
   232# reuse go mod download vcstest/hello@1234567890123456789012345678901234567890
   233! go mod download -reuse=hellononhash.json -x -json vcs-test.golang.org/git/hello.git@1234567890123456789012345678901234567890
   234! stderr 'git( .*)* fetch'
   235stdout '"Reuse": true'
   236stdout '"Version": "1234567890123456789012345678901234567890"'
   237stdout '"Error":.*unknown revision 1234567890123456789012345678901234567890'
   238stdout '"RepoSum": "r1:c0/9JCZ25lxoBiK3[+]3BhACU4giH49flcJmBynJ[+]Jvmc="'
   239! stdout '"(TagPrefix|TagSum|Ref|Hash)"'
   240! stdout '"(Dir|Info|GoMod|Zip)"'
   241
   242# reuse go mod download vcstest/hello@v0.0.0-20220101120101-123456789abc
   243! go mod download -reuse=hellononpseudo.json -x -json vcs-test.golang.org/git/hello.git@v0.0.0-20220101120101-123456789abc
   244! stderr 'git( .*)* fetch'
   245stdout '"Reuse": true'
   246stdout '"Version": "v0.0.0-20220101120101-123456789abc"'
   247stdout '"Error":.*unknown revision 123456789abc'
   248stdout '"RepoSum": "r1:c0/9JCZ25lxoBiK3[+]3BhACU4giH49flcJmBynJ[+]Jvmc="'
   249! stdout '"(TagPrefix|TagSum|Ref|Hash)"'
   250! stdout '"(Dir|Info|GoMod|Zip)"'
   251
   252# reuse go mod download vcstest/tagtests result
   253go mod download -reuse=tagtests.json -x -json vcs-test.golang.org/git/tagtests.git@latest
   254! stderr 'git( .*)* fetch'
   255stdout '"Reuse": true'
   256stdout '"Version": "v0.2.2"'
   257stdout '"Query": "latest"'
   258stdout '"VCS": "git"'
   259stdout '"URL": ".*/git/tagtests"'
   260! stdout '"TagPrefix"'
   261stdout '"TagSum": "t1:Dp7yRKDuE8WjG0429PN9hYWjqhy2te7P9Oki/sMEOGo="'
   262stdout '"Ref": "refs/tags/v0.2.2"'
   263stdout '"Hash": "59356c8cd18c5fe9a598167d98a6843e52d57952"'
   264! stdout '"(Dir|Info|GoMod|Zip)"'
   265
   266# reuse go mod download vcstest/tagtests@v0.2.2 result
   267go mod download -reuse=tagtestsv022.json -x -json vcs-test.golang.org/git/tagtests.git@v0.2.2
   268! stderr 'git( .*)* fetch'
   269stdout '"Reuse": true'
   270stdout '"Version": "v0.2.2"'
   271! stdout '"Query":'
   272stdout '"VCS": "git"'
   273stdout '"URL": ".*/git/tagtests"'
   274! stdout '"TagPrefix"'
   275! stdout '"TagSum"'
   276stdout '"Ref": "refs/tags/v0.2.2"'
   277stdout '"Hash": "59356c8cd18c5fe9a598167d98a6843e52d57952"'
   278! stdout '"(Dir|Info|GoMod|Zip)"'
   279
   280# reuse go mod download vcstest/tagtests@master result
   281go mod download -reuse=tagtestsmaster.json -x -json vcs-test.golang.org/git/tagtests.git@master
   282! stderr 'git( .*)* fetch'
   283stdout '"Reuse": true'
   284stdout '"Version": "v0.2.3-0.20190509225625-c7818c24fa2f"'
   285stdout '"Query": "master"'
   286stdout '"VCS": "git"'
   287stdout '"URL": ".*/git/tagtests"'
   288! stdout '"TagPrefix"'
   289stdout '"TagSum": "t1:Dp7yRKDuE8WjG0429PN9hYWjqhy2te7P9Oki/sMEOGo="'
   290stdout '"Ref": "refs/heads/master"'
   291stdout '"Hash": "c7818c24fa2f3f714c67d0a6d3e411c85a518d1f"'
   292! stdout '"(Dir|Info|GoMod|Zip)"'
   293
   294# reuse go mod download vcstest/tagtests@master result again with all.json
   295go mod download -reuse=all.json -x -json vcs-test.golang.org/git/tagtests.git@master
   296! stderr 'git( .*)* fetch'
   297stdout '"Reuse": true'
   298stdout '"Version": "v0.2.3-0.20190509225625-c7818c24fa2f"'
   299stdout '"Query": "master"'
   300stdout '"VCS": "git"'
   301stdout '"URL": ".*/git/tagtests"'
   302! stdout '"TagPrefix"'
   303stdout '"TagSum": "t1:Dp7yRKDuE8WjG0429PN9hYWjqhy2te7P9Oki/sMEOGo="'
   304stdout '"Ref": "refs/heads/master"'
   305stdout '"Hash": "c7818c24fa2f3f714c67d0a6d3e411c85a518d1f"'
   306! stdout '"(Dir|Info|GoMod|Zip)"'
   307
   308# go mod download vcstest/prefixtagtests result with json
   309go mod download -reuse=prefixtagtests.json -x -json vcs-test.golang.org/git/prefixtagtests.git/sub@latest
   310! stderr 'git( .*)* fetch'
   311stdout '"Version": "v0.0.10"'
   312stdout '"Query": "latest"'
   313stdout '"VCS": "git"'
   314stdout '"URL": ".*/git/prefixtagtests"'
   315stdout '"Subdir": "sub"'
   316stdout '"TagPrefix": "sub/"'
   317stdout '"TagSum": "t1:YGSbWkJ8dn9ORAr[+]BlKHFK/2ZhXLb9hVuYfTZ9D8C7g="'
   318stdout '"Ref": "refs/tags/sub/v0.0.10"'
   319stdout '"Hash": "2b7c4692e12c109263cab51b416fcc835ddd7eae"'
   320! stdout '"(Dir|Info|GoMod|Zip)"'
   321
   322# reuse the bulk results with all.json
   323! go mod download -reuse=all.json -json vcs-test.golang.org/git/hello.git@latest vcs-test.golang.org/git/hello.git/v9@latest vcs-test.golang.org/git/hello.git/sub/v9@latest vcs-test.golang.org/git/tagtests.git@latest vcs-test.golang.org/git/tagtests.git@v0.2.2 vcs-test.golang.org/git/tagtests.git@master
   324! stderr 'git( .*)* fetch'
   325stdout '"Reuse": true'
   326! stdout '"(Dir|Info|GoMod|Zip)"'
   327
   328# reuse attempt with stale hash should reinvoke git, not report reuse
   329cp tagtestsv022.json tagtestsv022badhash.json
   330replace '57952' '56952XXX' tagtestsv022badhash.json
   331go mod download -reuse=tagtestsv022badhash.json -x -json vcs-test.golang.org/git/tagtests.git@v0.2.2
   332stderr 'git( .*)* fetch'
   333! stdout '"Reuse": true'
   334stdout '"Version": "v0.2.2"'
   335! stdout '"Query"'
   336stdout '"VCS": "git"'
   337stdout '"URL": ".*/git/tagtests"'
   338! stdout '"(TagPrefix|TagSum)"'
   339stdout '"Ref": "refs/tags/v0.2.2"'
   340stdout '"Hash": "59356c8cd18c5fe9a598167d98a6843e52d57952"'
   341stdout '"Dir"'
   342stdout '"Info"'
   343stdout '"GoMod"'
   344stdout '"Zip"'
   345
   346# reuse with stale repo URL
   347cp tagtestsv022.json tagtestsv022badurl.json
   348replace 'git/tagtests\"' 'git/tagtestsXXX\"' tagtestsv022badurl.json
   349go mod download -reuse=tagtestsv022badurl.json -x -json vcs-test.golang.org/git/tagtests.git@v0.2.2
   350! stdout '"Reuse": true'
   351stdout '"URL": ".*/git/tagtests"'
   352stdout '"Dir"'
   353stdout '"Info"'
   354stdout '"GoMod"'
   355stdout '"Zip"'
   356
   357# reuse with stale VCS
   358cp tagtestsv022.json tagtestsv022badvcs.json
   359replace '\"git\"' '\"gitXXX\"' tagtestsv022badvcs.json
   360go mod download -reuse=tagtestsv022badvcs.json -x -json vcs-test.golang.org/git/tagtests.git@v0.2.2
   361! stdout '"Reuse": true'
   362stdout '"URL": ".*/git/tagtests"'
   363
   364# reuse with stale Dir
   365cp tagtestsv022.json tagtestsv022baddir.json
   366replace '\t\t\"Ref\":' '\t\t\"Subdir\": \"subdir\",\n\t\t\"Ref\":' tagtestsv022baddir.json
   367go mod download -reuse=tagtestsv022baddir.json -x -json vcs-test.golang.org/git/tagtests.git@v0.2.2
   368! stdout '"Reuse": true'
   369stdout '"URL": ".*/git/tagtests"'
   370
   371# reuse with stale TagSum
   372cp tagtests.json tagtestsbadtagsum.json
   373replace 'sMEOGo=' 'sMEoGo=XXX' tagtestsbadtagsum.json
   374go mod download -reuse=tagtestsbadtagsum.json -x -json vcs-test.golang.org/git/tagtests.git@latest
   375! stdout '"Reuse": true'
   376stdout '"TagSum": "t1:Dp7yRKDuE8WjG0429PN9hYWjqhy2te7P9Oki/sMEOGo="'

View as plain text