From 5e01565317861b703e04c9bea728e279c8766f99 Mon Sep 17 00:00:00 2001 From: Sebastian Dahlgren Date: Fri, 21 Jul 2017 08:29:14 +0530 Subject: [PATCH 1/3] Support semver suffixes 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 #827. --- cmd/dep/godep_importer_test.go | 41 +++++++++++++++++++++++++++++ internal/gps/source_manager.go | 2 +- internal/gps/source_manager_test.go | 8 +++++- 3 files changed, 49 insertions(+), 2 deletions(-) diff --git a/cmd/dep/godep_importer_test.go b/cmd/dep/godep_importer_test.go index fdbcf099ce..c03fc9a13f 100644 --- a/cmd/dep/godep_importer_test.go +++ b/cmd/dep/godep_importer_test.go @@ -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() diff --git a/internal/gps/source_manager.go b/internal/gps/source_manager.go index 9eabb19354..078a0b95cb 100644 --- a/internal/gps/source_manager.go +++ b/internal/gps/source_manager.go @@ -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 diff --git a/internal/gps/source_manager_test.go b/internal/gps/source_manager_test.go index bdd4709f3a..c788b411e5 100644 --- a/internal/gps/source_manager_test.go +++ b/internal/gps/source_manager_test.go @@ -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 From aad00e8de2ca0e3e23705008edd088a60ce90c72 Mon Sep 17 00:00:00 2001 From: Sebastian Dahlgren Date: Fri, 21 Jul 2017 08:33:16 +0530 Subject: [PATCH 2/3] Wrap too long comment --- internal/gps/source_manager.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/gps/source_manager.go b/internal/gps/source_manager.go index 078a0b95cb..c6840e9347 100644 --- a/internal/gps/source_manager.go +++ b/internal/gps/source_manager.go @@ -462,9 +462,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 { From a2c11c7cd46eaeab49b0899aae86db3e776b3e0e Mon Sep 17 00:00:00 2001 From: Sebastian Dahlgren Date: Sat, 22 Jul 2017 07:25:39 +0530 Subject: [PATCH 3/3] fixup! Support semver suffixes --- internal/gps/source_manager_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/gps/source_manager_test.go b/internal/gps/source_manager_test.go index c788b411e5..115985e73d 100644 --- a/internal/gps/source_manager_test.go +++ b/internal/gps/source_manager_test.go @@ -24,7 +24,7 @@ func TestSourceManager_InferConstraint(t *testing.T) { t.Fatal(err) } - svs, err := NewSemverConstraintIC(">=0.12.0, <=12.0.0-de4dcafe0") + svs, err := NewSemverConstraintIC("v0.12.0-12-de4dcafe0") if err != nil { t.Fatal(err) }