Skip to content
This repository has been archived by the owner on Sep 9, 2020. It is now read-only.

Implement vcs similar to go get #1717

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
/profile.out
/coverage.txt
release/
.idea/
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ NEW FEATURES:

BUG FIXES:

* `dep` resolves private repos (including `git`) similarly to `go get` ([#1716](https://github.com/golang/dep/issues/1716))

IMPROVEMENTS:

* Reduce network access by trusting local source information and only pulling
Expand Down
21 changes: 14 additions & 7 deletions gps/deduce.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ var (
//gcRegex = regexp.MustCompile(`^(?P<root>code\.google\.com/[pr]/(?P<project>[a-z0-9\-]+)(\.(?P<subrepo>[a-z0-9\-]+))?)(/[A-Za-z0-9_.\-]+)*$`)
jazzRegex = regexp.MustCompile(`^(?P<root>hub\.jazz\.net(/git/[a-z0-9]+/[A-Za-z0-9_.\-]+))((?:/[A-Za-z0-9_.\-]+)*)$`)
apacheRegex = regexp.MustCompile(`^(?P<root>git\.apache\.org(/[a-z0-9_.\-]+\.git))((?:/[A-Za-z0-9_.\-]+)*)$`)
vcsExtensionRegex = regexp.MustCompile(`^(?P<root>([a-z0-9.\-]+\.)+[a-z0-9.\-]+(:[0-9]+)?/[A-Za-z0-9_.\-/~]*?\.(?P<vcs>bzr|git|hg|svn))((?:/[A-Za-z0-9_.\-]+)*)$`)
vcsExtensionRegex = regexp.MustCompile(`^(?P<root>(?P<repo>([a-z0-9.\-]+\.)+[a-z0-9.\-]+(:[0-9]+)?(/~?[A-Za-z0-9_.\-]+)+?)\.(?P<vcs>bzr|fossil|git|hg|svn))(/~?[A-Za-z0-9_.\-]+)*$`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't actually support fossil - not sure there's much point in adding it.

)

// Other helper regexes
Expand Down Expand Up @@ -486,19 +486,26 @@ func (m vcsExtensionDeducer) deduceSource(path string, u *url.URL) (maybeSources
return nil, fmt.Errorf("%s contains no vcs extension hints for matching", path)
}

switch v[4] {
match := map[string]string{}
for i, name := range m.regexp.SubexpNames() {
if name != "" && match[name] == "" {
match[name] = v[i]
}
}

switch match["vcs"] {
case "git", "hg", "bzr":
x := strings.SplitN(v[1], "/", 2)
x := strings.SplitN(match["repo"], "/", 2)
// TODO(sdboyer) is this actually correct for bzr?
u.Host = x[0]
u.Path = "/" + x[1]

if u.Scheme != "" {
if !validateVCSScheme(u.Scheme, v[4]) {
return nil, fmt.Errorf("%s is not a valid scheme for accessing %s repositories (path %s)", u.Scheme, v[4], path)
if !validateVCSScheme(u.Scheme, match["vcs"]) {
return nil, fmt.Errorf("%s is not a valid scheme for accessing %s repositories (path %s)", u.Scheme, match["vcs"], path)
}

switch v[4] {
switch match["vcs"] {
case "git":
return maybeSources{maybeGitSource{url: u}}, nil
case "bzr":
Expand All @@ -512,7 +519,7 @@ func (m vcsExtensionDeducer) deduceSource(path string, u *url.URL) (maybeSources
var mb maybeSources
var f func(k int, u *url.URL)

switch v[4] {
switch match["vcs"] {
case "git":
schemes = gitSchemes
f = func(k int, u *url.URL) {
Expand Down
50 changes: 19 additions & 31 deletions gps/deduce_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,86 +396,74 @@ var pathDeductionFixtures = map[string][]pathDeductionFixture{
in: "foobar.com/baz.git",
root: "foobar.com/baz.git",
mb: maybeSources{
maybeGitSource{url: mkurl("https://foobar.com/baz.git")},
maybeGitSource{url: mkurl("ssh://foobar.com/baz.git")},
maybeGitSource{url: mkurl("git://foobar.com/baz.git")},
maybeGitSource{url: mkurl("http://foobar.com/baz.git")},
maybeGitSource{url: mkurl("https://foobar.com/baz")},
maybeGitSource{url: mkurl("ssh://foobar.com/baz")},
maybeGitSource{url: mkurl("git://foobar.com/baz")},
maybeGitSource{url: mkurl("http://foobar.com/baz")},
},
},
{
in: "foobar.com/baz.git/extra/path",
root: "foobar.com/baz.git",
mb: maybeSources{
maybeGitSource{url: mkurl("https://foobar.com/baz.git")},
maybeGitSource{url: mkurl("ssh://foobar.com/baz.git")},
maybeGitSource{url: mkurl("git://foobar.com/baz.git")},
maybeGitSource{url: mkurl("http://foobar.com/baz.git")},
maybeGitSource{url: mkurl("https://foobar.com/baz")},
maybeGitSource{url: mkurl("ssh://foobar.com/baz")},
maybeGitSource{url: mkurl("git://foobar.com/baz")},
maybeGitSource{url: mkurl("http://foobar.com/baz")},
},
},
{
in: "foobar.com/baz.bzr",
root: "foobar.com/baz.bzr",
mb: maybeSources{
maybeBzrSource{url: mkurl("https://foobar.com/baz.bzr")},
maybeBzrSource{url: mkurl("bzr+ssh://foobar.com/baz.bzr")},
maybeBzrSource{url: mkurl("bzr://foobar.com/baz.bzr")},
maybeBzrSource{url: mkurl("http://foobar.com/baz.bzr")},
maybeBzrSource{url: mkurl("https://foobar.com/baz")},
maybeBzrSource{url: mkurl("bzr+ssh://foobar.com/baz")},
maybeBzrSource{url: mkurl("bzr://foobar.com/baz")},
maybeBzrSource{url: mkurl("http://foobar.com/baz")},
},
},
{
in: "foo-bar.com/baz.hg",
root: "foo-bar.com/baz.hg",
mb: maybeSources{
maybeHgSource{url: mkurl("https://foo-bar.com/baz.hg")},
maybeHgSource{url: mkurl("ssh://foo-bar.com/baz.hg")},
maybeHgSource{url: mkurl("http://foo-bar.com/baz.hg")},
maybeHgSource{url: mkurl("https://foo-bar.com/baz")},
maybeHgSource{url: mkurl("ssh://foo-bar.com/baz")},
maybeHgSource{url: mkurl("http://foo-bar.com/baz")},
},
},
{
in: "[email protected]:baz.git",
root: "foobar.com/baz.git",
mb: maybeSources{
maybeGitSource{url: mkurl("ssh://[email protected]/baz.git")},
maybeGitSource{url: mkurl("ssh://[email protected]/baz")},
},
},
{
in: "bzr+ssh://foobar.com/baz.bzr",
root: "foobar.com/baz.bzr",
mb: maybeSources{
maybeBzrSource{url: mkurl("bzr+ssh://foobar.com/baz.bzr")},
maybeBzrSource{url: mkurl("bzr+ssh://foobar.com/baz")},
},
},
{
in: "ssh://foobar.com/baz.bzr",
root: "foobar.com/baz.bzr",
mb: maybeSources{
maybeBzrSource{url: mkurl("ssh://foobar.com/baz.bzr")},
maybeBzrSource{url: mkurl("ssh://foobar.com/baz")},
},
},
{
in: "https://foobar.com/baz.hg",
root: "foobar.com/baz.hg",
mb: maybeSources{
maybeHgSource{url: mkurl("https://foobar.com/baz.hg")},
maybeHgSource{url: mkurl("https://foobar.com/baz")},
},
},
{
in: "git://foobar.com/baz.hg",
root: "foobar.com/baz.hg",
srcerr: errors.New("git is not a valid scheme for accessing hg repositories (path foobar.com/baz.hg)"),
},
// who knows why anyone would do this, but having a second vcs ext
// shouldn't throw us off - only the first one counts
{
in: "foobar.com/baz.git/quark/quizzle.bzr/quorum",
root: "foobar.com/baz.git",
mb: maybeSources{
maybeGitSource{url: mkurl("https://foobar.com/baz.git")},
maybeGitSource{url: mkurl("ssh://foobar.com/baz.git")},
maybeGitSource{url: mkurl("git://foobar.com/baz.git")},
maybeGitSource{url: mkurl("http://foobar.com/baz.git")},
},
},
},
"vanity": {
// Vanity imports
Expand Down