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

Commit

Permalink
Support semver sufixes
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sebdah authored and carolynvs committed Jul 22, 2017
1 parent ccefd23 commit 167adc2
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 5 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
8 changes: 4 additions & 4 deletions internal/gps/source_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -498,9 +498,9 @@ func (sm *SourceMgr) DeduceProjectRoot(ip string) (ProjectRoot, error) {
return ProjectRoot(pd.root), err
}

// InferConstraint tries to puzzle out what kind of version is given in a string.
// Preference is given first for revisions, then branches, then semver constraints,
// and then plain tags.
// InferConstraint tries to puzzle out what kind of version is given in a
// string. Preference is given first for revisions, then branches, then semver
// constraints, and then plain tags.
func (sm *SourceMgr) InferConstraint(s string, pi ProjectIdentifier) (Constraint, error) {
slen := len(s)
if slen == 40 {
Expand All @@ -515,7 +515,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("v0.12.0-12-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 167adc2

Please sign in to comment.