From 7de341ce2e6dbaaaca076c7cd6f1df6bfc9aa360 Mon Sep 17 00:00:00 2001 From: Sunny Date: Mon, 20 Nov 2017 22:26:03 +0530 Subject: [PATCH] status: project status error out when project is not in lock --- cmd/dep/status.go | 6 +++++ .../final/Gopkg.lock | 27 +++++++++++++++++++ .../final/Gopkg.toml | 11 ++++++++ .../project_status_not_in_lock/final/main.go | 13 +++++++++ .../initial/Gopkg.lock | 27 +++++++++++++++++++ .../initial/Gopkg.toml | 11 ++++++++ .../initial/main.go | 13 +++++++++ .../project_status_not_in_lock/testcase.json | 12 +++++++++ 8 files changed, 120 insertions(+) create mode 100644 cmd/dep/testdata/harness_tests/status/project_status_not_in_lock/final/Gopkg.lock create mode 100644 cmd/dep/testdata/harness_tests/status/project_status_not_in_lock/final/Gopkg.toml create mode 100644 cmd/dep/testdata/harness_tests/status/project_status_not_in_lock/final/main.go create mode 100644 cmd/dep/testdata/harness_tests/status/project_status_not_in_lock/initial/Gopkg.lock create mode 100644 cmd/dep/testdata/harness_tests/status/project_status_not_in_lock/initial/Gopkg.toml create mode 100644 cmd/dep/testdata/harness_tests/status/project_status_not_in_lock/initial/main.go create mode 100644 cmd/dep/testdata/harness_tests/status/project_status_not_in_lock/testcase.json diff --git a/cmd/dep/status.go b/cmd/dep/status.go index ce17626350..f87bd43a90 100644 --- a/cmd/dep/status.go +++ b/cmd/dep/status.go @@ -897,6 +897,12 @@ func runProjectStatus(ctx *dep.Ctx, args []string, p *dep.Project, sm gps.Source if err != nil { return err } + + // Check if the target project is in the lock. + if !p.Lock.HasProjectWithRoot(pr) { + return errors.Errorf("%s is not in the lock file. Ensure that the project is being used and run `dep ensure` to generate a new lock file.", pr) + } + prs = append(prs, pr) } diff --git a/cmd/dep/testdata/harness_tests/status/project_status_not_in_lock/final/Gopkg.lock b/cmd/dep/testdata/harness_tests/status/project_status_not_in_lock/final/Gopkg.lock new file mode 100644 index 0000000000..326bc04f3c --- /dev/null +++ b/cmd/dep/testdata/harness_tests/status/project_status_not_in_lock/final/Gopkg.lock @@ -0,0 +1,27 @@ +# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. + + +[[projects]] + branch = "master" + name = "github.com/darkowlzz/deptest-project-status" + packages = ["pkgfoo"] + revision = "bddc1e2c8e4f0f264223389adf345d3858823677" + +[[projects]] + name = "github.com/sdboyer/deptest" + packages = ["."] + revision = "ff2948a2ac8f538c4ecd55962e919d1e13e74baf" + version = "v1.0.0" + +[[projects]] + name = "github.com/sdboyer/deptestdos" + packages = ["."] + revision = "5c607206be5decd28e6263ffffdcee067266015e" + version = "v2.0.0" + +[solve-meta] + analyzer-name = "dep" + analyzer-version = 1 + inputs-digest = "36a300774881748908b8209ab36dbfda73e8c51145d6bdbc9d87afd2655186c9" + solver-name = "gps-cdcl" + solver-version = 1 diff --git a/cmd/dep/testdata/harness_tests/status/project_status_not_in_lock/final/Gopkg.toml b/cmd/dep/testdata/harness_tests/status/project_status_not_in_lock/final/Gopkg.toml new file mode 100644 index 0000000000..6dbb73c194 --- /dev/null +++ b/cmd/dep/testdata/harness_tests/status/project_status_not_in_lock/final/Gopkg.toml @@ -0,0 +1,11 @@ +[[constraint]] + branch = "master" + name = "github.com/darkowlzz/deptest-project-status" + +[[constraint]] + name = "github.com/sdboyer/deptest" + version = "1.0.0" + +[[constraint]] + name = "github.com/sdboyer/deptestdos" + version = "2.0.0" diff --git a/cmd/dep/testdata/harness_tests/status/project_status_not_in_lock/final/main.go b/cmd/dep/testdata/harness_tests/status/project_status_not_in_lock/final/main.go new file mode 100644 index 0000000000..579d6d2a29 --- /dev/null +++ b/cmd/dep/testdata/harness_tests/status/project_status_not_in_lock/final/main.go @@ -0,0 +1,13 @@ +// Copyright 2017 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/darkowlzz/deptest-project-status/pkgfoo" + _ "github.com/sdboyer/deptest" + _ "github.com/sdboyer/deptestdos" +) + +func main() {} diff --git a/cmd/dep/testdata/harness_tests/status/project_status_not_in_lock/initial/Gopkg.lock b/cmd/dep/testdata/harness_tests/status/project_status_not_in_lock/initial/Gopkg.lock new file mode 100644 index 0000000000..326bc04f3c --- /dev/null +++ b/cmd/dep/testdata/harness_tests/status/project_status_not_in_lock/initial/Gopkg.lock @@ -0,0 +1,27 @@ +# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. + + +[[projects]] + branch = "master" + name = "github.com/darkowlzz/deptest-project-status" + packages = ["pkgfoo"] + revision = "bddc1e2c8e4f0f264223389adf345d3858823677" + +[[projects]] + name = "github.com/sdboyer/deptest" + packages = ["."] + revision = "ff2948a2ac8f538c4ecd55962e919d1e13e74baf" + version = "v1.0.0" + +[[projects]] + name = "github.com/sdboyer/deptestdos" + packages = ["."] + revision = "5c607206be5decd28e6263ffffdcee067266015e" + version = "v2.0.0" + +[solve-meta] + analyzer-name = "dep" + analyzer-version = 1 + inputs-digest = "36a300774881748908b8209ab36dbfda73e8c51145d6bdbc9d87afd2655186c9" + solver-name = "gps-cdcl" + solver-version = 1 diff --git a/cmd/dep/testdata/harness_tests/status/project_status_not_in_lock/initial/Gopkg.toml b/cmd/dep/testdata/harness_tests/status/project_status_not_in_lock/initial/Gopkg.toml new file mode 100644 index 0000000000..6dbb73c194 --- /dev/null +++ b/cmd/dep/testdata/harness_tests/status/project_status_not_in_lock/initial/Gopkg.toml @@ -0,0 +1,11 @@ +[[constraint]] + branch = "master" + name = "github.com/darkowlzz/deptest-project-status" + +[[constraint]] + name = "github.com/sdboyer/deptest" + version = "1.0.0" + +[[constraint]] + name = "github.com/sdboyer/deptestdos" + version = "2.0.0" diff --git a/cmd/dep/testdata/harness_tests/status/project_status_not_in_lock/initial/main.go b/cmd/dep/testdata/harness_tests/status/project_status_not_in_lock/initial/main.go new file mode 100644 index 0000000000..579d6d2a29 --- /dev/null +++ b/cmd/dep/testdata/harness_tests/status/project_status_not_in_lock/initial/main.go @@ -0,0 +1,13 @@ +// Copyright 2017 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/darkowlzz/deptest-project-status/pkgfoo" + _ "github.com/sdboyer/deptest" + _ "github.com/sdboyer/deptestdos" +) + +func main() {} diff --git a/cmd/dep/testdata/harness_tests/status/project_status_not_in_lock/testcase.json b/cmd/dep/testdata/harness_tests/status/project_status_not_in_lock/testcase.json new file mode 100644 index 0000000000..2bbbc78cdb --- /dev/null +++ b/cmd/dep/testdata/harness_tests/status/project_status_not_in_lock/testcase.json @@ -0,0 +1,12 @@ +{ + "commands": [ + ["ensure"], + ["status", "github.com/golang/dep"] + ], + "error-expected": "github.com/golang/dep is not in the lock file. Ensure that the project is being used and run `dep ensure` to generate a new lock file.", + "vendor-final": [ + "github.com/darkowlzz/deptest-project-status", + "github.com/sdboyer/deptest", + "github.com/sdboyer/deptestdos" + ] +}