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

Commit 01294a8

Browse files
authored
Merge pull request #500 from carolynvs/import-glide
Import glide configuration during init
2 parents 3cd62fc + 1ef8181 commit 01294a8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+12931
-499
lines changed

Gopkg.lock

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
name = "github.com/Masterminds/vcs"
77
version = "1.11.0"
88

9+
[[constraint]]
10+
branch = "v2"
11+
name = "github.com/go-yaml/yaml"
12+
913
[[constraint]]
1014
branch = "master"
1115
name = "github.com/pelletier/go-toml"

analyzer.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,19 @@ import (
1414

1515
type Analyzer struct{}
1616

17-
func (a Analyzer) DeriveManifestAndLock(path string, n gps.ProjectRoot) (gps.Manifest, gps.Lock, error) {
18-
// TODO: If we decide to support other tools manifest, this is where we would need
19-
// to add that support.
17+
// HasDepMetadata determines if a dep manifest exists at the specified path.
18+
func (a Analyzer) HasDepMetadata(path string) bool {
2019
mf := filepath.Join(path, ManifestName)
21-
if fileOK, err := fs.IsRegular(mf); err != nil || !fileOK {
22-
// Do not return an error, when does not exist.
20+
fileOK, err := fs.IsRegular(mf)
21+
return err == nil && fileOK
22+
}
23+
24+
func (a Analyzer) DeriveManifestAndLock(path string, n gps.ProjectRoot) (gps.Manifest, gps.Lock, error) {
25+
if !a.HasDepMetadata(path) {
2326
return nil, nil, nil
2427
}
25-
f, err := os.Open(mf)
28+
29+
f, err := os.Open(filepath.Join(path, ManifestName))
2630
if err != nil {
2731
return nil, nil, err
2832
}

cmd/dep/ensure.go

Lines changed: 44 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -262,76 +262,70 @@ func (s *stringSlice) Set(value string) error {
262262
}
263263

264264
func getProjectConstraint(arg string, sm gps.SourceManager) (gps.ProjectConstraint, error) {
265-
constraint := gps.ProjectConstraint{
265+
emptyPC := gps.ProjectConstraint{
266266
Constraint: gps.Any(), // default to any; avoids panics later
267267
}
268268

269269
// try to split on '@'
270-
var versionStr string
270+
// When there is no `@`, use any version
271+
versionStr := "*"
271272
atIndex := strings.Index(arg, "@")
272273
if atIndex > 0 {
273274
parts := strings.SplitN(arg, "@", 2)
274275
arg = parts[0]
275276
versionStr = parts[1]
276-
constraint.Constraint = deduceConstraint(parts[1])
277277
}
278-
// TODO: What if there is no @, assume default branch (which may not be master) ?
278+
279279
// TODO: if we decide to keep equals.....
280280

281281
// split on colon if there is a network location
282+
var source string
282283
colonIndex := strings.Index(arg, ":")
283284
if colonIndex > 0 {
284285
parts := strings.SplitN(arg, ":", 2)
285286
arg = parts[0]
286-
constraint.Ident.Source = parts[1]
287+
source = parts[1]
287288
}
288289

289290
pr, err := sm.DeduceProjectRoot(arg)
290291
if err != nil {
291-
return constraint, errors.Wrapf(err, "could not infer project root from dependency path: %s", arg) // this should go through to the user
292+
return emptyPC, errors.Wrapf(err, "could not infer project root from dependency path: %s", arg) // this should go through to the user
292293
}
293294

294295
if string(pr) != arg {
295-
return constraint, errors.Errorf("dependency path %s is not a project root, try %s instead", arg, pr)
296+
return emptyPC, errors.Errorf("dependency path %s is not a project root, try %s instead", arg, pr)
296297
}
297298

298-
constraint.Ident.ProjectRoot = gps.ProjectRoot(arg)
299-
300-
// Below we are checking if the constraint we deduced was valid.
301-
if v, ok := constraint.Constraint.(gps.Version); ok && versionStr != "" {
302-
if v.Type() == gps.IsVersion {
303-
// we hit the fall through case in deduce constraint, let's call out to network
304-
// and get the package's versions
305-
versions, err := sm.ListVersions(constraint.Ident)
306-
if err != nil {
307-
return constraint, errors.Wrapf(err, "list versions for %s", arg) // means repo does not exist
308-
}
299+
pi := gps.ProjectIdentifier{ProjectRoot: pr, Source: source}
300+
c, err := deduceConstraint(versionStr, pi, sm)
301+
if err != nil {
302+
return emptyPC, err
303+
}
304+
return gps.ProjectConstraint{Ident: pi, Constraint: c}, nil
305+
}
309306

310-
var found bool
311-
for _, version := range versions {
312-
if versionStr == version.String() {
313-
found = true
314-
constraint.Constraint = version.Unpair()
315-
break
316-
}
317-
}
307+
// deduceConstraint tries to puzzle out what kind of version is given in a string -
308+
// semver, a revision, or as a fallback, a plain tag
309+
func deduceConstraint(s string, pi gps.ProjectIdentifier, sm gps.SourceManager) (gps.Constraint, error) {
310+
if s == "" {
311+
// Find the default branch
312+
versions, err := sm.ListVersions(pi)
313+
if err != nil {
314+
return nil, errors.Wrapf(err, "list versions for %s(%s)", pi.ProjectRoot, pi.Source) // means repo does not exist
315+
}
318316

319-
if !found {
320-
return constraint, errors.Errorf("%s is not a valid version for the package %s", versionStr, arg)
317+
gps.SortPairedForUpgrade(versions)
318+
for _, v := range versions {
319+
if v.Type() == gps.IsBranch {
320+
return v.Unpair(), nil
321321
}
322322
}
323323
}
324324

325-
return constraint, nil
326-
}
327-
328-
// deduceConstraint tries to puzzle out what kind of version is given in a string -
329-
// semver, a revision, or as a fallback, a plain tag
330-
func deduceConstraint(s string) gps.Constraint {
331325
// always semver if we can
332326
c, err := gps.NewSemverConstraintIC(s)
333327
if err == nil {
334-
return c
328+
return c, nil
335329
}
336330

337331
slen := len(s)
@@ -340,7 +334,7 @@ func deduceConstraint(s string) gps.Constraint {
340334
// Whether or not it's intended to be a SHA1 digest, this is a
341335
// valid byte sequence for that, so go with Revision. This
342336
// covers git and hg
343-
return gps.Revision(s)
337+
return gps.Revision(s), nil
344338
}
345339
}
346340
// Next, try for bzr, which has a three-component GUID separated by
@@ -351,20 +345,29 @@ func deduceConstraint(s string) gps.Constraint {
351345
i3 := strings.LastIndex(s, "-")
352346
// Skip if - is last char, otherwise this would panic on bounds err
353347
if slen == i3+1 {
354-
return gps.NewVersion(s)
348+
return gps.NewVersion(s), nil
355349
}
356350

357351
i2 := strings.LastIndex(s[:i3], "-")
358352
if _, err = strconv.ParseUint(s[i2+1:i3], 10, 64); err == nil {
359353
// Getting this far means it'd pretty much be nuts if it's not a
360354
// bzr rev, so don't bother parsing the email.
361-
return gps.Revision(s)
355+
return gps.Revision(s), nil
362356
}
363357
}
364358

365-
// If not a plain SHA1 or bzr custom GUID, assume a plain version.
366-
// TODO: if there is amgibuity here, then prompt the user?
367-
return gps.NewVersion(s)
359+
// call out to network and get the package's versions
360+
versions, err := sm.ListVersions(pi)
361+
if err != nil {
362+
return nil, errors.Wrapf(err, "list versions for %s(%s)", pi.ProjectRoot, pi.Source) // means repo does not exist
363+
}
364+
365+
for _, version := range versions {
366+
if s == version.String() {
367+
return version.Unpair(), nil
368+
}
369+
}
370+
return nil, errors.Errorf("%s is not a valid version for the package %s(%s)", s, pi.ProjectRoot, pi.Source)
368371
}
369372

370373
func checkErrors(m map[string]pkgtree.PackageOrErr) error {

cmd/dep/ensure_test.go

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,37 @@ import (
99
"testing"
1010

1111
"github.com/golang/dep/internal/gps"
12+
"github.com/golang/dep/internal/test"
1213
)
1314

1415
func TestDeduceConstraint(t *testing.T) {
1516
t.Parallel()
17+
h := test.NewHelper(t)
18+
cacheDir := "gps-repocache"
19+
h.TempDir(cacheDir)
20+
sm, err := gps.NewSourceManager(h.Path(cacheDir))
21+
h.Must(err)
1622

17-
sv, err := gps.NewSemverConstraintIC("v1.2.3")
23+
sv, err := gps.NewSemverConstraintIC("v0.8.1")
1824
if err != nil {
1925
t.Fatal(err)
2026
}
2127

2228
constraints := map[string]gps.Constraint{
23-
"v1.2.3": sv,
29+
"v0.8.1": sv,
30+
"master": gps.NewBranch("master"),
2431
"5b3352dc16517996fb951394bcbbe913a2a616e3": gps.Revision("5b3352dc16517996fb951394bcbbe913a2a616e3"),
2532

26-
// valid bzr revs
33+
// valid bzr rev
2734
"jess@linux.com-20161116211307-wiuilyamo9ian0m7": gps.Revision("jess@linux.com-20161116211307-wiuilyamo9ian0m7"),
28-
29-
// invalid bzr revs
30-
"go4@golang.org-lskjdfnkjsdnf-ksjdfnskjdfn": gps.NewVersion("go4@golang.org-lskjdfnkjsdnf-ksjdfnskjdfn"),
31-
"go4@golang.org-sadfasdf-": gps.NewVersion("go4@golang.org-sadfasdf-"),
32-
"20120425195858-psty8c35ve2oej8t": gps.NewVersion("20120425195858-psty8c35ve2oej8t"),
35+
// invalid bzr rev
36+
"go4@golang.org-sadfasdf-": gps.NewVersion("go4@golang.org-sadfasdf-"),
3337
}
3438

39+
pi := gps.ProjectIdentifier{ProjectRoot: "github.com/sdboyer/deptest"}
3540
for str, want := range constraints {
36-
got := deduceConstraint(str)
41+
got, err := deduceConstraint(str, pi, sm)
42+
h.Must(err)
3743

3844
wantT := reflect.TypeOf(want)
3945
gotT := reflect.TypeOf(got)
@@ -45,3 +51,26 @@ func TestDeduceConstraint(t *testing.T) {
4551
}
4652
}
4753
}
54+
55+
func TestDeduceConstraint_InvalidInput(t *testing.T) {
56+
h := test.NewHelper(t)
57+
58+
cacheDir := "gps-repocache"
59+
h.TempDir(cacheDir)
60+
sm, err := gps.NewSourceManager(h.Path(cacheDir))
61+
h.Must(err)
62+
63+
constraints := []string{
64+
// invalid bzr revs
65+
"go4@golang.org-lskjdfnkjsdnf-ksjdfnskjdfn",
66+
"20120425195858-psty8c35ve2oej8t",
67+
}
68+
69+
pi := gps.ProjectIdentifier{ProjectRoot: "github.com/sdboyer/deptest"}
70+
for _, str := range constraints {
71+
_, err := deduceConstraint(str, pi, sm)
72+
if err == nil {
73+
t.Errorf("expected %s to produce an error", str)
74+
}
75+
}
76+
}

0 commit comments

Comments
 (0)