Skip to content

Commit

Permalink
Merge pull request golang#1414 from arbourd/omit-empty-constraint
Browse files Browse the repository at this point in the history
Skip empty constraints
  • Loading branch information
carolynvs authored Dec 3, 2017
2 parents e69d6e8 + ac45fa2 commit bd15b89
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 48 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ IMPROVEMENTS:
* Log as dependencies are pre-fetched during dep init ([#1176](https://github.com/golang/dep/pull/1176)).
* Make the gps package importable ([#1349](https://github.com/golang/dep/pull/1349)).
* Improve file copy performance by not forcing a file sync (PR #1408).
* Skip empty constraints during import ([#1414](https://github.com/golang/dep/pull/1349))

# v0.3.2

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
ignored = ["github.com/golang/notexist/samples","github.com/sdboyer/dep-test"]

[[constraint]]
name = "github.com/carolynvs/deptest-subpkg"

[[constraint]]
name = "github.com/sdboyer/deptestdos"
version = "2.0.0"

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

[[constraint]]
name = "github.com/sdboyer/deptestdos"
version = "2.0.0"

[[constraint]]
branch = "v2"
Expand Down
15 changes: 11 additions & 4 deletions internal/importers/base/importer.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,18 @@ func (i *Importer) ImportPackages(packages []ImportedPackage, defaultConstraintF
pc.Constraint = gps.Any()
}

i.Manifest.Constraints[pc.Ident.ProjectRoot] = gps.ProjectProperties{
Source: pc.Ident.Source,
Constraint: pc.Constraint,
// Add constraint to manifest that is not empty (has a branch, version or source)
if !gps.IsAny(pc.Constraint) || pc.Ident.Source != "" {
i.Manifest.Constraints[pc.Ident.ProjectRoot] = gps.ProjectProperties{
Source: pc.Ident.Source,
Constraint: pc.Constraint,
}
fb.NewConstraintFeedback(pc, fb.DepTypeImported).LogFeedback(i.Logger)
} else {
if i.Verbose {
i.Logger.Printf(" Skipping import of %v because its constraint is empty.\n", pc.Ident)
}
}
fb.NewConstraintFeedback(pc, fb.DepTypeImported).LogFeedback(i.Logger)

if version != nil {
lp := gps.NewLockedProject(pc.Ident, version, nil)
Expand Down
50 changes: 21 additions & 29 deletions internal/importers/base/importer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,10 @@ func TestBaseImporter_ImportProjects(t *testing.T) {
importertest.TestCase
projects []ImportedPackage
}{
"tag constraints are ignored": {
"tag constraints are skipped": {
importertest.TestCase{
WantConstraint: "*",
WantVersion: importertest.Beta1Tag,
WantRevision: importertest.Beta1Rev,
WantVersion: importertest.Beta1Tag,
WantRevision: importertest.Beta1Rev,
},
[]ImportedPackage{
{
Expand All @@ -162,9 +161,8 @@ func TestBaseImporter_ImportProjects(t *testing.T) {
},
"tag lock hints Lock to tagged revision": {
importertest.TestCase{
WantConstraint: "*",
WantVersion: importertest.Beta1Tag,
WantRevision: importertest.Beta1Rev,
WantVersion: importertest.Beta1Tag,
WantRevision: importertest.Beta1Rev,
},
[]ImportedPackage{
{
Expand All @@ -175,8 +173,7 @@ func TestBaseImporter_ImportProjects(t *testing.T) {
},
"untagged revision ignores range constraint": {
importertest.TestCase{
WantConstraint: "*",
WantRevision: importertest.UntaggedRev,
WantRevision: importertest.UntaggedRev,
},
[]ImportedPackage{
{
Expand Down Expand Up @@ -270,11 +267,10 @@ func TestBaseImporter_ImportProjects(t *testing.T) {
},
},
},
"Revision constraints are ignored": {
"Revision constraints are skipped": {
importertest.TestCase{
WantConstraint: "*",
WantVersion: importertest.V1Tag,
WantRevision: importertest.V1Rev,
WantVersion: importertest.V1Tag,
WantRevision: importertest.V1Rev,
},
[]ImportedPackage{
{
Expand All @@ -298,11 +294,10 @@ func TestBaseImporter_ImportProjects(t *testing.T) {
},
},
},
"Non-matching semver constraint is ignored": {
"Non-matching semver constraint is skipped": {
importertest.TestCase{
WantConstraint: "*",
WantVersion: importertest.V1Tag,
WantRevision: importertest.V1Rev,
WantVersion: importertest.V1Tag,
WantRevision: importertest.V1Rev,
},
[]ImportedPackage{
{
Expand All @@ -312,10 +307,9 @@ func TestBaseImporter_ImportProjects(t *testing.T) {
},
},
},
"git describe constraint is ignored": {
"git describe constraint is skipped": {
importertest.TestCase{
WantConstraint: "*",
WantRevision: importertest.UntaggedRev,
WantRevision: importertest.UntaggedRev,
},
[]ImportedPackage{
{
Expand All @@ -342,10 +336,9 @@ func TestBaseImporter_ImportProjects(t *testing.T) {
},
},
},
"ignore duplicate packages": {
"skip duplicate packages": {
importertest.TestCase{
WantConstraint: "*",
WantRevision: importertest.UntaggedRev,
WantRevision: importertest.UntaggedRev,
},
[]ImportedPackage{
{
Expand All @@ -360,8 +353,8 @@ func TestBaseImporter_ImportProjects(t *testing.T) {
},
"skip empty lock hints": {
importertest.TestCase{
WantConstraint: "*",
WantRevision: "",
WantRevision: "",
WantWarning: "constraint is empty",
},
[]ImportedPackage{
{
Expand All @@ -382,10 +375,10 @@ func TestBaseImporter_ImportProjects(t *testing.T) {
},
},
},
"ignore default source": {
"skip default source": {
importertest.TestCase{
WantConstraint: "*",
WantSourceRepo: "",
WantWarning: "constraint is empty",
},
[]ImportedPackage{
{
Expand All @@ -394,9 +387,8 @@ func TestBaseImporter_ImportProjects(t *testing.T) {
},
},
},
"ignore vendored source": {
"skip vendored source": {
importertest.TestCase{
WantConstraint: "*",
WantSourceRepo: "",
WantWarning: "vendored sources aren't supported",
},
Expand Down
6 changes: 2 additions & 4 deletions internal/importers/glide/importer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,7 @@ func TestGlideConfig_Convert(t *testing.T) {
}},
glideLock{},
importertest.TestCase{
WantConstraint: "*",
WantWarning: "specified an os",
WantWarning: "specified an os",
},
},
"warn unused arch field": {
Expand All @@ -152,8 +151,7 @@ func TestGlideConfig_Convert(t *testing.T) {
}},
glideLock{},
importertest.TestCase{
WantConstraint: "*",
WantWarning: "specified an arch",
WantWarning: "specified an arch",
},
},
}
Expand Down
1 change: 0 additions & 1 deletion internal/importers/glide/testdata/golden.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ Converting from glide.yaml and glide.lock...
Trying v0.8.1 (3f4c3be) as initial lock for imported dep github.com/sdboyer/deptest
Using ^2.0.0 as initial constraint for imported dep github.com/sdboyer/deptestdos
Trying v2.0.0 (5c60720) as initial lock for imported dep github.com/sdboyer/deptestdos
Using * as initial constraint for imported dep github.com/golang/lint
Trying * (cb00e56) as initial lock for imported dep github.com/golang/lint
2 changes: 1 addition & 1 deletion internal/importers/govendor/importer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func TestGovendorConfig_Convert(t *testing.T) {
},
},
importertest.TestCase{
WantConstraint: "*",
WantWarning: "constraint is empty",
},
},
}
Expand Down
5 changes: 2 additions & 3 deletions internal/importers/gvt/importer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,8 @@ func TestGvtConfig_Convert(t *testing.T) {
},
"package with HEAD branch": {
importertest.TestCase{
WantConstraint: "*",
WantRevision: importertest.V1Rev,
WantVersion: importertest.V1Tag,
WantRevision: importertest.V1Rev,
WantVersion: importertest.V1Tag,
},
gvtManifest{
Deps: []gvtPkg{
Expand Down
1 change: 0 additions & 1 deletion internal/importers/gvt/testdata/golden.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
Detected gb/gvt configuration files...
Converting from vendor/manifest ...
Using * as initial constraint for imported dep github.com/sdboyer/deptest
Trying v0.8.1 (3f4c3be) as initial lock for imported dep github.com/sdboyer/deptest
Using ^2.0.0 as initial constraint for imported dep github.com/sdboyer/deptestdos
Trying v2.0.0 (5c60720) as initial lock for imported dep github.com/sdboyer/deptestdos
Expand Down

0 comments on commit bd15b89

Please sign in to comment.