Support packages that are not hosted in repos root (#1)

VCSroot should point to a repository, not to the package full path.

git-svn-id: file:///srv/svn/repo/toyohime/trunk@67 922d331f-388e-da47-97a9-ad700dc0b8b9
This commit is contained in:
mremond 2018-01-11 13:01:32 +00:00
parent d3cb2a54b5
commit c04bf0744a
2 changed files with 15 additions and 3 deletions

View File

@ -42,13 +42,24 @@ func Redirect(vcs, importPath, repoRoot string) http.Handler {
http.NotFound(w, r)
return
}
vcsroot := ""
vcsroot := repoRoot
if strings.HasPrefix(r.URL.Path, "/cmd/") {
path = r.URL.Path[4:]
vcsroot = repoRoot + path
} else {
vcsroot = repoRoot + r.URL.Path
path = r.URL.Path
}
shortPath := strings.Split(path, "/")
f := func(c rune) bool {
return c == '/'
}
shortPath = strings.FieldsFunc(path, f)
if (len(shortPath) > 0) {
vcsroot = repoRoot + "/" + shortPath[0]
}
if r.FormValue("go-get") != "1" {
url := "https://godoc.org/" + r.Host + r.URL.Path
http.Redirect(w, r, url, http.StatusTemporaryRedirect)

View File

@ -75,6 +75,7 @@ func TestGoTool(t *testing.T) {
{"/set?go-get=1", "kkn.fi/set git https://github.com/kare/set"},
{"/cmd/vanity?go-get=1", "kkn.fi/cmd/vanity git https://github.com/kare/vanity"},
{"/cmd/tcpproxy?go-get=1", "kkn.fi/cmd/tcpproxy git https://github.com/kare/tcpproxy"},
{"/pkg/subpkg?go-get=1", "kkn.fi/pkg/subpkg git https://github.com/kare/pkg"},
}
for _, test := range tests {
res := httptest.NewRecorder()