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

Commit 167adc2

Browse files
sebdahcarolynvs
authored andcommitted
Support semver sufixes
This addresses an issue where the godep importer would confuse semver suffixes for being bzr revisions. Now we have stricter checks on the bzr revision checks which will be able to distinguish between semver with a suffix and a bzr revision. The new check enforces bzr revisions to contain an @ symbol.
1 parent ccefd23 commit 167adc2

File tree

3 files changed

+52
-5
lines changed

3 files changed

+52
-5
lines changed

cmd/dep/godep_importer_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,47 @@ func TestGodepConfig_ConvertProject(t *testing.T) {
161161
}
162162
}
163163

164+
func TestGodepConfig_ConvertProject_WithSemverSuffix(t *testing.T) {
165+
h := test.NewHelper(t)
166+
defer h.Cleanup()
167+
168+
ctx := newTestContext(h)
169+
sm, err := ctx.SourceManager()
170+
h.Must(err)
171+
defer sm.Release()
172+
173+
g := newGodepImporter(discardLogger, true, sm)
174+
g.json = godepJSON{
175+
Imports: []godepPackage{
176+
{
177+
ImportPath: "github.com/sdboyer/deptest",
178+
Rev: "ff2948a2ac8f538c4ecd55962e919d1e13e74baf",
179+
Comment: "v1.12.0-12-g2fd980e",
180+
},
181+
},
182+
}
183+
184+
manifest, lock, err := g.convert("")
185+
if err != nil {
186+
t.Fatal(err)
187+
}
188+
189+
d, ok := manifest.Constraints["github.com/sdboyer/deptest"]
190+
if !ok {
191+
t.Fatal("Expected the manifest to have a dependency for 'github.com/sdboyer/deptest' but got none")
192+
}
193+
194+
v := d.Constraint.String()
195+
if v != ">=1.12.0, <=12.0.0-g2fd980e" {
196+
t.Fatalf("Expected manifest constraint to be >=1.12.0, <=12.0.0-g2fd980e, got %s", v)
197+
}
198+
199+
p := lock.P[0]
200+
if p.Ident().ProjectRoot != "github.com/sdboyer/deptest" {
201+
t.Fatalf("Expected the lock to have a project for 'github.com/sdboyer/deptest' but got '%s'", p.Ident().ProjectRoot)
202+
}
203+
}
204+
164205
func TestGodepConfig_ConvertProject_EmptyComment(t *testing.T) {
165206
h := test.NewHelper(t)
166207
defer h.Cleanup()

internal/gps/source_manager.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -498,9 +498,9 @@ func (sm *SourceMgr) DeduceProjectRoot(ip string) (ProjectRoot, error) {
498498
return ProjectRoot(pd.root), err
499499
}
500500

501-
// InferConstraint tries to puzzle out what kind of version is given in a string.
502-
// Preference is given first for revisions, then branches, then semver constraints,
503-
// and then plain tags.
501+
// InferConstraint tries to puzzle out what kind of version is given in a
502+
// string. Preference is given first for revisions, then branches, then semver
503+
// constraints, and then plain tags.
504504
func (sm *SourceMgr) InferConstraint(s string, pi ProjectIdentifier) (Constraint, error) {
505505
slen := len(s)
506506
if slen == 40 {
@@ -515,7 +515,7 @@ func (sm *SourceMgr) InferConstraint(s string, pi ProjectIdentifier) (Constraint
515515
// Next, try for bzr, which has a three-component GUID separated by
516516
// dashes. There should be two, but the email part could contain
517517
// internal dashes
518-
if strings.Count(s, "-") >= 2 {
518+
if strings.Contains(s, "@") && strings.Count(s, "-") >= 2 {
519519
// Work from the back to avoid potential confusion from the email
520520
i3 := strings.LastIndex(s, "-")
521521
// Skip if - is last char, otherwise this would panic on bounds err

internal/gps/source_manager_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,16 @@ func TestSourceManager_InferConstraint(t *testing.T) {
2424
t.Fatal(err)
2525
}
2626

27+
svs, err := NewSemverConstraintIC("v0.12.0-12-de4dcafe0")
28+
if err != nil {
29+
t.Fatal(err)
30+
}
31+
2732
constraints := map[string]Constraint{
2833
"v0.8.1": sv,
2934
"v2": NewBranch("v2"),
30-
"master": NewBranch("master"),
35+
"v0.12.0-12-de4dcafe0": svs,
36+
"master": NewBranch("master"),
3137
"5b3352dc16517996fb951394bcbbe913a2a616e3": Revision("5b3352dc16517996fb951394bcbbe913a2a616e3"),
3238

3339
// valid bzr rev

0 commit comments

Comments
 (0)