diff --git a/cmd/dep/status.go b/cmd/dep/status.go index 24f100f93f..0ed9893930 100644 --- a/cmd/dep/status.go +++ b/cmd/dep/status.go @@ -799,6 +799,11 @@ func collectConstraints(ctx *dep.Ctx, p *dep.Project, sm gps.SourceManager) (con // Iterate through the project constraints to get individual dependency // project and constraint values. for pr, pp := range pc { + // Check if the project constraint is imported in the root project + if _, ok := directDeps[string(pr)]; !ok { + continue + } + tempCC := append( constraintCollection[string(pr)], projectConstraint{proj.Ident().ProjectRoot, pp.Constraint}, diff --git a/cmd/dep/status_test.go b/cmd/dep/status_test.go index 140a642574..b06cddb544 100644 --- a/cmd/dep/status_test.go +++ b/cmd/dep/status_test.go @@ -382,6 +382,26 @@ func TestCollectConstraints(t *testing.T) { }, wantErr: true, }, + { + name: "collect only applicable constraints", + lock: dep.Lock{ + P: []gps.LockedProject{ + gps.NewLockedProject( + gps.ProjectIdentifier{ProjectRoot: gps.ProjectRoot("github.com/darkowlzz/dep-applicable-constraints")}, + gps.NewVersion("v1.0.0"), + []string{"."}, + ), + }, + }, + wantConstraints: constraintsCollection{ + "github.com/boltdb/bolt": []projectConstraint{ + {"github.com/darkowlzz/dep-applicable-constraints", gps.NewBranch("master")}, + }, + "github.com/sdboyer/deptest": []projectConstraint{ + {"github.com/darkowlzz/dep-applicable-constraints", ver08}, + }, + }, + }, } h := test.NewHelper(t) @@ -389,6 +409,17 @@ func TestCollectConstraints(t *testing.T) { h.TempDir("src") pwd := h.Path(".") + h.TempFile(filepath.Join("src", "dep.go"), ` + package dep + import ( + _ "github.com/boltdb/bolt" + _ "github.com/sdboyer/deptest" + _ "github.com/sdboyer/dep-test" + _ "github.com/sdboyer/deptestdos" + ) + type FooBar int + `) + discardLogger := log.New(ioutil.Discard, "", 0) ctx := &dep.Ctx{