Merge pull request #361 from shurcooL/followup-fix-repo-clone-url
gosrc: Use unmodified clone URL from import meta tag for cloning.
diff --git a/gosrc/gosrc.go b/gosrc/gosrc.go
index 9ae9fca..41b41b3 100644
--- a/gosrc/gosrc.go
+++ b/gosrc/gosrc.go
@@ -324,13 +324,17 @@
}
}
- repo := strings.TrimSuffix(im.repo, "."+im.vcs)
- i := strings.Index(repo, "://")
+ // clonePath is the repo URL from import meta tag, with the "scheme://" prefix removed.
+ // It should be used for cloning repositories.
+ // repo is the repo URL from import meta tag, with the "scheme://" prefix removed, and
+ // a possible ".vcs" suffix trimmed.
+ i := strings.Index(im.repo, "://")
if i < 0 {
return nil, NotFoundError{Message: "bad repo URL: " + im.repo}
}
- proto := repo[:i]
- repo = repo[i+len("://"):]
+ proto := im.repo[:i]
+ clonePath := im.repo[i+len("://"):]
+ repo := strings.TrimSuffix(clonePath, "."+im.vcs)
dirName := importPath[len(im.projectRoot):]
resolvedPath := repo + dirName
@@ -340,6 +344,7 @@
match := map[string]string{
"dir": dirName,
"importPath": importPath,
+ "clonePath": clonePath,
"repo": repo,
"scheme": proto,
"vcs": im.vcs,
diff --git a/gosrc/vcs.go b/gosrc/vcs.go
index ce872f9..252047f 100644
--- a/gosrc/vcs.go
+++ b/gosrc/vcs.go
@@ -101,7 +101,7 @@
type vcsCmd struct {
schemes []string
- download func([]string, string, string) (string, string, error)
+ download func([]string, string, string, string) (string, string, error)
}
var vcsCmds = map[string]*vcsCmd{
@@ -117,11 +117,11 @@
var lsremoteRe = regexp.MustCompile(`(?m)^([0-9a-f]{40})\s+refs/(?:tags|heads)/(.+)$`)
-func downloadGit(schemes []string, repo, savedEtag string) (string, string, error) {
+func downloadGit(schemes []string, clonePath, repo, savedEtag string) (string, string, error) {
var p []byte
var scheme string
for i := range schemes {
- cmd := exec.Command("git", "ls-remote", "--heads", "--tags", schemes[i]+"://"+repo)
+ cmd := exec.Command("git", "ls-remote", "--heads", "--tags", schemes[i]+"://"+clonePath)
log.Println(strings.Join(cmd.Args, " "))
var err error
p, err = outputWithTimeout(cmd, lsRemoteTimeout)
@@ -158,7 +158,7 @@
if err := os.MkdirAll(dir, 0777); err != nil {
return "", "", err
}
- cmd := exec.Command("git", "clone", scheme+"://"+repo, dir)
+ cmd := exec.Command("git", "clone", scheme+"://"+clonePath, dir)
log.Println(strings.Join(cmd.Args, " "))
if err := runWithTimeout(cmd, cloneTimeout); err != nil {
return "", "", err
@@ -183,12 +183,12 @@
return tag, etag, nil
}
-func downloadSVN(schemes []string, repo, savedEtag string) (string, string, error) {
+func downloadSVN(schemes []string, clonePath, repo, savedEtag string) (string, string, error) {
var scheme string
var revno string
for i := range schemes {
var err error
- revno, err = getSVNRevision(schemes[i] + "://" + repo)
+ revno, err = getSVNRevision(schemes[i] + "://" + clonePath)
if err == nil {
scheme = schemes[i]
break
@@ -212,7 +212,7 @@
if err := os.MkdirAll(dir, 0777); err != nil {
return "", "", err
}
- cmd := exec.Command("svn", "checkout", scheme+"://"+repo, "-r", revno, dir)
+ cmd := exec.Command("svn", "checkout", scheme+"://"+clonePath, "-r", revno, dir)
log.Println(strings.Join(cmd.Args, " "))
if err := runWithTimeout(cmd, cloneTimeout); err != nil {
return "", "", err
@@ -271,7 +271,7 @@
// Download and checkout.
- tag, etag, err := cmd.download(schemes, match["repo"], etagSaved)
+ tag, etag, err := cmd.download(schemes, match["clonePath"], match["repo"], etagSaved)
if err != nil {
return nil, err
}