Skip to content

Commit

Permalink
Support semver suffixes
Browse files Browse the repository at this point in the history
This commit 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.

Closes golang#827.
  • Loading branch information
sebdah committed Jul 21, 2017
1 parent 4f8c074 commit 5e01565
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
41 changes: 41 additions & 0 deletions cmd/dep/godep_importer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,47 @@ func TestGodepConfig_ConvertProject(t *testing.T) {
}
}

func TestGodepConfig_ConvertProject_WithSemverSuffix(t *testing.T) {
h := test.NewHelper(t)
defer h.Cleanup()

ctx := newTestContext(h)
sm, err := ctx.SourceManager()
h.Must(err)
defer sm.Release()

g := newGodepImporter(discardLogger, true, sm)
g.json = godepJSON{
Imports: []godepPackage{
{
ImportPath: "github.com/sdboyer/deptest",
Rev: "ff2948a2ac8f538c4ecd55962e919d1e13e74baf",
Comment: "v1.12.0-12-g2fd980e",
},
},
}

manifest, lock, err := g.convert("")
if err != nil {
t.Fatal(err)
}

d, ok := manifest.Constraints["github.com/sdboyer/deptest"]
if !ok {
t.Fatal("Expected the manifest to have a dependency for 'github.com/sdboyer/deptest' but got none")
}

v := d.Constraint.String()
if v != ">=1.12.0, <=12.0.0-g2fd980e" {
t.Fatalf("Expected manifest constraint to be >=1.12.0, <=12.0.0-g2fd980e, got %s", v)
}

p := lock.P[0]
if p.Ident().ProjectRoot != "github.com/sdboyer/deptest" {
t.Fatalf("Expected the lock to have a project for 'github.com/sdboyer/deptest' but got '%s'", p.Ident().ProjectRoot)
}
}

func TestGodepConfig_ConvertProject_EmptyComment(t *testing.T) {
h := test.NewHelper(t)
defer h.Cleanup()
Expand Down
2 changes: 1 addition & 1 deletion internal/gps/source_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ func (sm *SourceMgr) InferConstraint(s string, pi ProjectIdentifier) (Constraint
// Next, try for bzr, which has a three-component GUID separated by
// dashes. There should be two, but the email part could contain
// internal dashes
if strings.Count(s, "-") >= 2 {
if strings.Contains(s, "@") && strings.Count(s, "-") >= 2 {
// Work from the back to avoid potential confusion from the email
i3 := strings.LastIndex(s, "-")
// Skip if - is last char, otherwise this would panic on bounds err
Expand Down
8 changes: 7 additions & 1 deletion internal/gps/source_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,16 @@ func TestSourceManager_InferConstraint(t *testing.T) {
t.Fatal(err)
}

svs, err := NewSemverConstraintIC(">=0.12.0, <=12.0.0-de4dcafe0")
if err != nil {
t.Fatal(err)
}

constraints := map[string]Constraint{
"v0.8.1": sv,
"v2": NewBranch("v2"),
"master": NewBranch("master"),
"v0.12.0-12-de4dcafe0": svs,
"master": NewBranch("master"),
"5b3352dc16517996fb951394bcbbe913a2a616e3": Revision("5b3352dc16517996fb951394bcbbe913a2a616e3"),

// valid bzr rev
Expand Down

0 comments on commit 5e01565

Please sign in to comment.