Merge pull request #393 from franciscocpg/ppa-dist
Instructions to install from PPA
diff --git a/dependency/resolver.go b/dependency/resolver.go
index 2b919b0..e97ddd6 100644
--- a/dependency/resolver.go
+++ b/dependency/resolver.go
@@ -793,7 +793,7 @@
// Why does a Google product get a special case build mode with a local
// package?
LocAppengine
- // LocRelative indicates the packge is a relative directory
+ // LocRelative indicates the package is a relative directory
LocRelative
)
diff --git a/repo/cache.go b/repo/cache.go
index 43ec644..babd1c2 100644
--- a/repo/cache.go
+++ b/repo/cache.go
@@ -7,9 +7,9 @@
"net/url"
"os"
"path/filepath"
+ "regexp"
"strings"
"time"
-
//"github.com/Masterminds/glide/msg"
)
@@ -36,22 +36,34 @@
}
*/
+// scpSyntaxRe matches the SCP-like addresses used to access repos over SSH.
+var scpSyntaxRe = regexp.MustCompile(`^([a-zA-Z0-9_]+)@([a-zA-Z0-9._-]+):(.*)$`)
+
// Pass in a repo location and get a cache key from it.
func cacheCreateKey(repo string) (string, error) {
- // A url needs a scheme. A git repo such as
- // git@github.com:Masterminds/cookoo.git reworked to the url parser.
- c := strings.Contains(repo, "://")
- if !c {
- repo = "ssh://" + repo
+ var u *url.URL
+ var err error
+ var strip bool
+ if m := scpSyntaxRe.FindStringSubmatch(repo); m != nil {
+ // Match SCP-like syntax and convert it to a URL.
+ // Eg, "git@github.com:user/repo" becomes
+ // "ssh://git@github.com/user/repo".
+ u = &url.URL{
+ Scheme: "ssh",
+ User: url.User(m[1]),
+ Host: m[2],
+ Path: "/" + m[3],
+ }
+ strip = true
+ } else {
+ u, err = url.Parse(repo)
+ if err != nil {
+ return "", err
+ }
}
- u, err := url.Parse(repo)
- if err != nil {
- return "", err
- }
-
- if !c {
+ if strip {
u.Scheme = ""
}
diff --git a/util/normalizename_test.go b/util/normalizename_test.go
index fe1f77b..c6f4d02 100644
--- a/util/normalizename_test.go
+++ b/util/normalizename_test.go
@@ -5,17 +5,44 @@
)
func TestNormalizeName(t *testing.T) {
- packages := map[string]string{
- "github.com/Masterminds/cookoo/web/io/foo": "github.com/Masterminds/cookoo",
- "golang.org/x/crypto/ssh": "golang.org/x/crypto",
- "incomplete/example": "incomplete/example",
- "net": "net",
+ packages := []struct {
+ input string
+ root string
+ extra string
+ }{
+ {
+ input: "github.com/Masterminds/cookoo/web/io/foo",
+ root: "github.com/Masterminds/cookoo",
+ extra: "web/io/foo",
+ },
+ {
+ input: `github.com\Masterminds\cookoo\web\io\foo`,
+ root: "github.com/Masterminds/cookoo",
+ extra: "web/io/foo",
+ },
+ {
+ input: "golang.org/x/crypto/ssh",
+ root: "golang.org/x/crypto",
+ extra: "ssh",
+ },
+ {
+ input: "incomplete/example",
+ root: "incomplete/example",
+ extra: "",
+ },
+ {
+ input: "net",
+ root: "net",
+ extra: "",
+ },
}
- for start, expected := range packages {
- if finish, extra := NormalizeName(start); expected != finish {
- t.Errorf("Expected '%s', got '%s'", expected, finish)
- } else if start != finish && start != finish+"/"+extra {
- t.Errorf("Expected %s to end with %s", finish, extra)
+ for _, test := range packages {
+ root, extra := NormalizeName(test.input)
+ if root != test.root {
+ t.Errorf("%s: Expected root '%s', got '%s'", test.input, test.root, root)
+ }
+ if extra != test.extra {
+ t.Errorf("%s: Expected extra '%s', got '%s'", test.input, test.extra, extra)
}
}
}
diff --git a/util/util.go b/util/util.go
index e32fffa..a5b346f 100644
--- a/util/util.go
+++ b/util/util.go
@@ -29,13 +29,17 @@
}
}
+func toSlash(v string) string {
+ return strings.Replace(v, "\\", "/", -1)
+}
+
// GetRootFromPackage retrives the top level package from a name.
//
// From a package name find the root repo. For example,
// the package github.com/Masterminds/cookoo/io has a root repo
// at github.com/Masterminds/cookoo
func GetRootFromPackage(pkg string) string {
- pkg = filepath.ToSlash(pkg)
+ pkg = toSlash(pkg)
for _, v := range vcsList {
m := v.regex.FindStringSubmatch(pkg)
if m == nil {
@@ -307,10 +311,11 @@
if err == nil {
p := filepath.Join(b.GOROOT, "src", name)
if _, err := os.Stat(p); err == nil {
- return filepath.ToSlash(name), ""
+ return toSlash(name), ""
}
}
+ name = toSlash(name)
root := GetRootFromPackage(name)
extra := strings.TrimPrefix(name, root)
if len(extra) > 0 && extra != "/" {