From dae0e9d6e97cb25efc082142455ec37023aaeab8 Mon Sep 17 00:00:00 2001 From: Christopher O'Toole Date: Fri, 1 Dec 2017 13:48:57 -0600 Subject: [PATCH 1/3] Fix how dep status print revision constraints Before this fix revision constraints would be printed as an Any constraint ("*") instead of as the revision itself. --- cmd/dep/status.go | 10 +++++++--- cmd/dep/status_test.go | 7 +++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/cmd/dep/status.go b/cmd/dep/status.go index 9cae286bea..60eabaee89 100644 --- a/cmd/dep/status.go +++ b/cmd/dep/status.go @@ -487,9 +487,13 @@ func runStatusAll(ctx *dep.Ctx, out outputter, p *dep.Project, sm gps.SourceMana bs.hasOverride = true bs.Constraint = pp.Constraint } else { - bs.Constraint = gps.Any() - for _, c := range cm[bs.ProjectRoot] { - bs.Constraint = c.Constraint.Intersect(bs.Constraint) + if pp, has := p.Manifest.Constraints[proj.Ident().ProjectRoot]; has && pp.Constraint != nil { + bs.Constraint = pp.Constraint + } else { + bs.Constraint = gps.Any() + for _, c := range cm[bs.ProjectRoot] { + bs.Constraint = c.Constraint.Intersect(bs.Constraint) + } } } diff --git a/cmd/dep/status_test.go b/cmd/dep/status_test.go index 6f0eb3f4d0..37504cbf8b 100644 --- a/cmd/dep/status_test.go +++ b/cmd/dep/status_test.go @@ -187,6 +187,13 @@ func TestBasicStatusGetConsolidatedConstraint(t *testing.T) { }, wantConstraint: "1.2.1 (override)", }, + { + name: "BasicStatus with Revision Constraint", + basicStatus: BasicStatus{ + Constraint: gps.Revision("ddeb6f5d27091ff291b16232e99076a64fb375b8"), + }, + wantConstraint: "ddeb6f5", + }, } for _, tc := range testCases { From 5092d416444f3e1ac3bcbce873f9acc9558a2b34 Mon Sep 17 00:00:00 2001 From: Christopher O'Toole Date: Fri, 1 Dec 2017 14:19:34 -0600 Subject: [PATCH 2/3] Simplify else / if by using else if --- cmd/dep/status.go | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/cmd/dep/status.go b/cmd/dep/status.go index 60eabaee89..254c066001 100644 --- a/cmd/dep/status.go +++ b/cmd/dep/status.go @@ -486,14 +486,12 @@ func runStatusAll(ctx *dep.Ctx, out outputter, p *dep.Project, sm gps.SourceMana if pp, has := p.Manifest.Ovr[proj.Ident().ProjectRoot]; has && pp.Constraint != nil { bs.hasOverride = true bs.Constraint = pp.Constraint + } else if pp, has := p.Manifest.Constraints[proj.Ident().ProjectRoot]; has && pp.Constraint != nil { + bs.Constraint = pp.Constraint } else { - if pp, has := p.Manifest.Constraints[proj.Ident().ProjectRoot]; has && pp.Constraint != nil { - bs.Constraint = pp.Constraint - } else { - bs.Constraint = gps.Any() - for _, c := range cm[bs.ProjectRoot] { - bs.Constraint = c.Constraint.Intersect(bs.Constraint) - } + bs.Constraint = gps.Any() + for _, c := range cm[bs.ProjectRoot] { + bs.Constraint = c.Constraint.Intersect(bs.Constraint) } } From b5e10242b4e5b93dab8cd638d1565668c317fa0f Mon Sep 17 00:00:00 2001 From: Christopher O'Toole Date: Tue, 12 Dec 2017 11:16:58 -0600 Subject: [PATCH 3/3] Add integration test --- cmd/dep/status.go | 1 + .../revision_constraint/final/Gopkg.lock | 20 +++++++++++++++++++ .../revision_constraint/final/Gopkg.toml | 3 +++ .../revision_constraint/initial/Gopkg.lock | 20 +++++++++++++++++++ .../revision_constraint/initial/Gopkg.toml | 3 +++ .../revision_constraint/initial/main.go | 12 +++++++++++ .../status/revision_constraint/stdout.txt | 3 +++ .../status/revision_constraint/testcase.json | 11 ++++++++++ 8 files changed, 73 insertions(+) create mode 100644 cmd/dep/testdata/harness_tests/status/revision_constraint/final/Gopkg.lock create mode 100644 cmd/dep/testdata/harness_tests/status/revision_constraint/final/Gopkg.toml create mode 100644 cmd/dep/testdata/harness_tests/status/revision_constraint/initial/Gopkg.lock create mode 100644 cmd/dep/testdata/harness_tests/status/revision_constraint/initial/Gopkg.toml create mode 100644 cmd/dep/testdata/harness_tests/status/revision_constraint/initial/main.go create mode 100644 cmd/dep/testdata/harness_tests/status/revision_constraint/stdout.txt create mode 100644 cmd/dep/testdata/harness_tests/status/revision_constraint/testcase.json diff --git a/cmd/dep/status.go b/cmd/dep/status.go index 254c066001..7e2fe0b383 100644 --- a/cmd/dep/status.go +++ b/cmd/dep/status.go @@ -487,6 +487,7 @@ func runStatusAll(ctx *dep.Ctx, out outputter, p *dep.Project, sm gps.SourceMana bs.hasOverride = true bs.Constraint = pp.Constraint } else if pp, has := p.Manifest.Constraints[proj.Ident().ProjectRoot]; has && pp.Constraint != nil { + // If the manifest has a constraint then set that as the constraint. bs.Constraint = pp.Constraint } else { bs.Constraint = gps.Any() diff --git a/cmd/dep/testdata/harness_tests/status/revision_constraint/final/Gopkg.lock b/cmd/dep/testdata/harness_tests/status/revision_constraint/final/Gopkg.lock new file mode 100644 index 0000000000..204b990861 --- /dev/null +++ b/cmd/dep/testdata/harness_tests/status/revision_constraint/final/Gopkg.lock @@ -0,0 +1,20 @@ +# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. + + +[[projects]] + name = "github.com/sdboyer/deptest" + packages = ["."] + revision = "ff2948a2ac8f538c4ecd55962e919d1e13e74baf" + version = "v1.0.0" + +[[projects]] + name = "github.com/sdboyer/deptestdos" + packages = ["."] + revision = "a0196baa11ea047dd65037287451d36b861b00ea" + +[solve-meta] + analyzer-name = "dep" + analyzer-version = 1 + inputs-digest = "a64abd431f23d6fbc8d83aef311d33ab12b3a6c74a46c271e89c2542c98bbb9a" + solver-name = "gps-cdcl" + solver-version = 1 diff --git a/cmd/dep/testdata/harness_tests/status/revision_constraint/final/Gopkg.toml b/cmd/dep/testdata/harness_tests/status/revision_constraint/final/Gopkg.toml new file mode 100644 index 0000000000..1dbd51fcc9 --- /dev/null +++ b/cmd/dep/testdata/harness_tests/status/revision_constraint/final/Gopkg.toml @@ -0,0 +1,3 @@ +[[constraint]] + name = "github.com/sdboyer/deptestdos" + revision = "a0196baa11ea047dd65037287451d36b861b00ea" diff --git a/cmd/dep/testdata/harness_tests/status/revision_constraint/initial/Gopkg.lock b/cmd/dep/testdata/harness_tests/status/revision_constraint/initial/Gopkg.lock new file mode 100644 index 0000000000..204b990861 --- /dev/null +++ b/cmd/dep/testdata/harness_tests/status/revision_constraint/initial/Gopkg.lock @@ -0,0 +1,20 @@ +# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. + + +[[projects]] + name = "github.com/sdboyer/deptest" + packages = ["."] + revision = "ff2948a2ac8f538c4ecd55962e919d1e13e74baf" + version = "v1.0.0" + +[[projects]] + name = "github.com/sdboyer/deptestdos" + packages = ["."] + revision = "a0196baa11ea047dd65037287451d36b861b00ea" + +[solve-meta] + analyzer-name = "dep" + analyzer-version = 1 + inputs-digest = "a64abd431f23d6fbc8d83aef311d33ab12b3a6c74a46c271e89c2542c98bbb9a" + solver-name = "gps-cdcl" + solver-version = 1 diff --git a/cmd/dep/testdata/harness_tests/status/revision_constraint/initial/Gopkg.toml b/cmd/dep/testdata/harness_tests/status/revision_constraint/initial/Gopkg.toml new file mode 100644 index 0000000000..1dbd51fcc9 --- /dev/null +++ b/cmd/dep/testdata/harness_tests/status/revision_constraint/initial/Gopkg.toml @@ -0,0 +1,3 @@ +[[constraint]] + name = "github.com/sdboyer/deptestdos" + revision = "a0196baa11ea047dd65037287451d36b861b00ea" diff --git a/cmd/dep/testdata/harness_tests/status/revision_constraint/initial/main.go b/cmd/dep/testdata/harness_tests/status/revision_constraint/initial/main.go new file mode 100644 index 0000000000..6ebfee7840 --- /dev/null +++ b/cmd/dep/testdata/harness_tests/status/revision_constraint/initial/main.go @@ -0,0 +1,12 @@ +// Copyright 2016 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + _ "github.com/sdboyer/deptestdos" +) + +func main() { +} diff --git a/cmd/dep/testdata/harness_tests/status/revision_constraint/stdout.txt b/cmd/dep/testdata/harness_tests/status/revision_constraint/stdout.txt new file mode 100644 index 0000000000..7a63488b05 --- /dev/null +++ b/cmd/dep/testdata/harness_tests/status/revision_constraint/stdout.txt @@ -0,0 +1,3 @@ +PROJECT CONSTRAINT VERSION REVISION LATEST PKGS USED +github.com/sdboyer/deptest v1.0.0 v1.0.0 ff2948a ff2948a 1 +github.com/sdboyer/deptestdos a0196ba a0196ba 1 diff --git a/cmd/dep/testdata/harness_tests/status/revision_constraint/testcase.json b/cmd/dep/testdata/harness_tests/status/revision_constraint/testcase.json new file mode 100644 index 0000000000..e1f1eadeeb --- /dev/null +++ b/cmd/dep/testdata/harness_tests/status/revision_constraint/testcase.json @@ -0,0 +1,11 @@ +{ + "commands": [ + ["ensure"], + ["status"] + ], + "error-expected": "", + "vendor-final": [ + "github.com/sdboyer/deptest", + "github.com/sdboyer/deptestdos" + ] +}