ok=false
fi
+# Test that 'go get -u' reports moved packages.
+testmove() {
+ vcs=$1
+ url=$2
+ base=$3
+ config=$4
+
+ TEST go get -u notices $vcs package that moved
+ d=$(mktemp -d -t testgoXXX)
+ mkdir -p $d/src
+ if ! GOPATH=$d ./testgo get -d $url; then
+ echo 'go get -d $url failed'
+ ok=false
+ elif ! GOPATH=$d ./testgo get -d -u $url; then
+ echo 'go get -d -u $url failed'
+ ok=false
+ else
+ set +e
+ case "$vcs" in
+ svn)
+ # SVN doesn't believe in text files so we can't just edit the config.
+ # Check out a different repo into the wrong place.
+ rm -rf $d/src/code.google.com/p/rsc-svn
+ GOPATH=$d ./testgo get -d -u code.google.com/p/rsc-svn2/trunk
+ mv $d/src/code.google.com/p/rsc-svn2 $d/src/code.google.com/p/rsc-svn
+ ;;
+ *)
+ echo '1,$s;'"$base"';'"$base"'XXX;
+w
+q' | ed $d/src/$config >/dev/null 2>&1
+ esac
+ set -e
+
+ if GOPATH=$d ./testgo get -d -u $url 2>$d/err; then
+ echo "go get -d -u $url succeeded with wrong remote repo"
+ cat $d/err
+ ok=false
+ elif ! grep 'should be from' $d/err >/dev/null; then
+ echo "go get -d -u $url failed for wrong reason"
+ cat $d/err
+ ok=false
+ fi
+ fi
+ rm -rf $d
+}
+
+testmove hg rsc.io/x86/x86asm x86 rsc.io/x86/.hg/hgrc
+testmove git rsc.io/pdf pdf rsc.io/pdf/.git/config
+testmove svn code.google.com/p/rsc-svn/trunk - -
+
export GOPATH=$(pwd)/testdata/importcom
TEST 'import comment - match'
if ! ./testgo build ./testdata/importcom/works.go; then
scheme []string
pingCmd string
+
+ remoteRepo func(v *vcsCmd, rootDir string) (remoteRepo string, err error)
}
// A tagCmd describes a command to list available tags
tagSyncCmd: "update -r {tag}",
tagSyncDefault: "update default",
- scheme: []string{"https", "http", "ssh"},
- pingCmd: "identify {scheme}://{repo}",
+ scheme: []string{"https", "http", "ssh"},
+ pingCmd: "identify {scheme}://{repo}",
+ remoteRepo: hgRemoteRepo,
+}
+
+func hgRemoteRepo(vcsHg *vcsCmd, rootDir string) (remoteRepo string, err error) {
+ out, err := vcsHg.runOutput(rootDir, "paths default")
+ if err != nil {
+ return "", err
+ }
+ return strings.TrimSpace(string(out)), nil
}
// vcsGit describes how to use Git.
tagSyncCmd: "checkout {tag}",
tagSyncDefault: "checkout master",
- scheme: []string{"git", "https", "http", "git+ssh"},
- pingCmd: "ls-remote {scheme}://{repo}",
+ scheme: []string{"git", "https", "http", "git+ssh"},
+ pingCmd: "ls-remote {scheme}://{repo}",
+ remoteRepo: gitRemoteRepo,
+}
+
+func gitRemoteRepo(vcsGit *vcsCmd, rootDir string) (remoteRepo string, err error) {
+ outb, err := vcsGit.runOutput(rootDir, "remote -v")
+ if err != nil {
+ return "", err
+ }
+ out := string(outb)
+
+ // Expect:
+ // origin https://github.com/rsc/pdf (fetch)
+ // origin https://github.com/rsc/pdf (push)
+ // use first line only.
+
+ if !strings.HasPrefix(out, "origin\t") {
+ return "", fmt.Errorf("unable to parse output of git remote -v")
+ }
+ out = strings.TrimPrefix(out, "origin\t")
+ i := strings.Index(out, "\n")
+ if i < 0 {
+ return "", fmt.Errorf("unable to parse output of git remote -v")
+ }
+ out = out[:i]
+ i = strings.LastIndex(out, " ")
+ if i < 0 {
+ return "", fmt.Errorf("unable to parse output of git remote -v")
+ }
+ out = out[:i]
+ return strings.TrimSpace(string(out)), nil
}
// vcsBzr describes how to use Bazaar.
// There is no tag command in subversion.
// The branch information is all in the path names.
- scheme: []string{"https", "http", "svn", "svn+ssh"},
- pingCmd: "info {scheme}://{repo}",
+ scheme: []string{"https", "http", "svn", "svn+ssh"},
+ pingCmd: "info {scheme}://{repo}",
+ remoteRepo: svnRemoteRepo,
+}
+
+func svnRemoteRepo(vcsSvn *vcsCmd, rootDir string) (remoteRepo string, err error) {
+ outb, err := vcsSvn.runOutput(rootDir, "info")
+ if err != nil {
+ return "", err
+ }
+ out := string(outb)
+
+ // Expect:
+ // ...
+ // Repository Root: <URL>
+ // ...
+
+ i := strings.Index(out, "\nRepository Root: ")
+ if i < 0 {
+ return "", fmt.Errorf("unable to parse output of svn info")
+ }
+ out = out[i+len("\nRepository Root: "):]
+ i = strings.Index(out, "\n")
+ if i < 0 {
+ return "", fmt.Errorf("unable to parse output of svn info")
+ }
+ out = out[:i]
+ return strings.TrimSpace(string(out)), nil
}
func (v *vcsCmd) String() string {