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

Address mixup between bzr revisions and semver suffixes #869

Merged
merged 3 commits into from
Jul 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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 {
Expand All @@ -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 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉 Nice catch!

// 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