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

     1  env GO111MODULE=off
     2  
     3  # Test that 'go get -u' reports packages whose VCS configurations do not
     4  # match their import paths.
     5  
     6  [!net] skip
     7  [short] skip
     8  
     9  # We need to execute a custom Go program to break the config files.
    10  #
    11  # git will ask for a username and password when we run 'go get -d -f -u',
    12  # so we also need to set GIT_ASKPASS. Conveniently, a single binary can
    13  # perform both tasks!
    14  
    15  go build -o replace.exe replace
    16  env GIT_ASKPASS=$PWD/replace.exe
    17  
    18  
    19  # Test that 'go get -u' reports moved git packages.
    20  
    21  [exec:git] go get -d rsc.io/pdf
    22  [exec:git] go get -d -u rsc.io/pdf
    23  [exec:git] exec ./replace.exe pdf rsc.io/pdf/.git/config
    24  
    25  [exec:git] ! go get -d -u rsc.io/pdf
    26  [exec:git] stderr 'is a custom import path for'
    27  [exec:git] ! go get -d -f -u rsc.io/pdf
    28  [exec:git] stderr 'validating server certificate|[nN]ot [fF]ound'
    29  
    30  
    31  # Test that 'go get -u' reports moved Mercurial packages.
    32  
    33  [exec:hg] go get -d vcs-test.golang.org/go/custom-hg-hello
    34  [exec:hg] go get -d -u vcs-test.golang.org/go/custom-hg-hello
    35  [exec:hg] exec ./replace.exe custom-hg-hello vcs-test.golang.org/go/custom-hg-hello/.hg/hgrc
    36  
    37  [exec:hg] ! go get -d -u vcs-test.golang.org/go/custom-hg-hello
    38  [exec:hg] stderr 'is a custom import path for'
    39  [exec:hg] ! go get -d -f -u vcs-test.golang.org/go/custom-hg-hello
    40  [exec:hg] stderr 'validating server certificate|[nN]ot [fF]ound'
    41  
    42  
    43  -- replace/replace.go --
    44  package main
    45  
    46  import (
    47  	"bytes"
    48  	"log"
    49  	"os"
    50  )
    51  
    52  func main() {
    53  	if len(os.Args) < 3 {
    54  		return
    55  	}
    56  
    57  	base := []byte(os.Args[1])
    58  	path := os.Args[2]
    59  	data, err := os.ReadFile(path)
    60  	if err != nil {
    61  		log.Fatal(err)
    62  	}
    63  	err = os.WriteFile(path, bytes.ReplaceAll(data, base, append(base, "XXX"...)), 0644)
    64  	if err != nil {
    65  		log.Fatal(err)
    66  	}
    67  }
    68  

View as plain text