Commit 86c08e96 authored by Andrew Gerrand's avatar Andrew Gerrand

goinstall: support googlecode subrepos and add repo match tests

goinstall: don't hit network unless a checkout or update is required

R=rsc, rogpeppe
CC=golang-dev
https://golang.org/cl/5343042
parent 7c161b05
......@@ -79,6 +79,10 @@ Goinstall recognizes packages from a few common code hosting sites:
import "project.googlecode.com/svn/trunk"
import "project.googlecode.com/svn/trunk/sub/directory"
Google Code Project Hosting sub-repositories:
import "code.google.com/p/project.subrepo/sub/directory
Launchpad (Bazaar)
import "launchpad.net/project"
......
This diff is collapsed.
// Copyright 2011 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"bytes"
"errors"
"io/ioutil"
"net/http"
"testing"
)
var FindPublicRepoTests = []struct {
pkg string
vcs, root, url string
transport *testTransport
}{
{
"repo.googlecode.com/hg/path/foo",
"hg",
"repo.googlecode.com/hg",
"https://repo.googlecode.com/hg",
nil,
},
{
"repo.googlecode.com/svn/path",
"svn",
"repo.googlecode.com/svn",
"https://repo.googlecode.com/svn",
nil,
},
{
"repo.googlecode.com/git",
"git",
"repo.googlecode.com/git",
"https://repo.googlecode.com/git",
nil,
},
{
"code.google.com/p/repo.sub/path",
"hg",
"code.google.com/p/repo.sub",
"https://code.google.com/p/repo.sub",
&testTransport{
"https://code.google.com/p/repo/source/checkout?repo=sub",
`<tt id="checkoutcmd">hg clone https://...`,
},
},
{
"bitbucket.org/user/repo/path/foo",
"hg",
"bitbucket.org/user/repo",
"http://bitbucket.org/user/repo",
&testTransport{
"https://api.bitbucket.org/1.0/repositories/user/repo",
`{"scm": "hg"}`,
},
},
{
"bitbucket.org/user/repo/path/foo",
"git",
"bitbucket.org/user/repo",
"http://bitbucket.org/user/repo.git",
&testTransport{
"https://api.bitbucket.org/1.0/repositories/user/repo",
`{"scm": "git"}`,
},
},
{
"github.com/user/repo/path/foo",
"git",
"github.com/user/repo",
"http://github.com/user/repo.git",
nil,
},
{
"launchpad.net/project/series/path",
"bzr",
"launchpad.net/project/series",
"https://launchpad.net/project/series",
nil,
},
{
"launchpad.net/~user/project/branch/path",
"bzr",
"launchpad.net/~user/project/branch",
"https://launchpad.net/~user/project/branch",
nil,
},
}
func TestFindPublicRepo(t *testing.T) {
for _, test := range FindPublicRepoTests {
client := http.DefaultClient
if test.transport != nil {
client = &http.Client{Transport: test.transport}
}
repo, err := findPublicRepo(test.pkg)
if err != nil {
t.Errorf("findPublicRepo(%s): error: %v", test.pkg, err)
continue
}
if repo == nil {
t.Errorf("%s: got nil match", test.pkg)
continue
}
url, root, vcs, err := repo.Repo(client)
if err != nil {
t.Errorf("%s: repo.Repo error: %v", test.pkg, err)
continue
}
if v := vcsMap[test.vcs]; vcs != v {
t.Errorf("%s: got vcs=%v, want %v", test.pkg, vcs, v)
}
if root != test.root {
t.Errorf("%s: got root=%v, want %v", test.pkg, root, test.root)
}
if url != test.url {
t.Errorf("%s: got url=%v, want %v", test.pkg, url, test.url)
}
}
}
type testTransport struct {
expectURL string
responseBody string
}
func (t *testTransport) RoundTrip(req *http.Request) (*http.Response, error) {
if g, e := req.URL.String(), t.expectURL; g != e {
return nil, errors.New("want " + e)
}
body := ioutil.NopCloser(bytes.NewBufferString(t.responseBody))
return &http.Response{
StatusCode: http.StatusOK,
Body: body,
}, nil
}
......@@ -218,8 +218,9 @@ func install(pkg, parent string) {
} else {
// Test if this is a public repository
// (for reporting to dashboard).
m, _ := findPublicRepo(pkg)
public = m != nil
repo, e := findPublicRepo(pkg)
public = repo != nil
err = e
}
}
if err != nil {
......@@ -334,3 +335,18 @@ func genRun(dir string, stdin []byte, arg []string, quiet bool) error {
}
return nil
}
// isRemote returns true if the first part of the package name looks like a
// hostname - i.e. contains at least one '.' and the last part is at least 2
// characters.
func isRemote(pkg string) bool {
parts := strings.SplitN(pkg, "/", 2)
if len(parts) != 2 {
return false
}
parts = strings.Split(parts[0], ".")
if len(parts) < 2 || len(parts[len(parts)-1]) < 2 {
return false
}
return true
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment