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..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 { @@ -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..115985e73d 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("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