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

Commit a9121da

Browse files
authored
Merge pull request #1952 from sdboyer/noverify
dep: Introduce noverify field to Gopkg.toml
2 parents 5cd267f + baebed0 commit a9121da

File tree

80 files changed

+610
-92
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+610
-92
lines changed

cmd/dep/check.go

+30-6
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ can be disabled with -skip-lock and -skip-vendor, respectively.
3333
3434
(See https://golang.github.io/dep/docs/ensure-mechanics.html#staying-in-sync for
3535
more information on what it means to be "in sync.")
36+
37+
If your workflow necessitates that you modify the contents of vendor, you can
38+
force check to ignore hash mismatches on a per-project basis by naming
39+
project roots in Gopkg.toml's "noverify" list.
3640
`
3741

3842
type checkCommand struct {
@@ -132,23 +136,42 @@ func (cmd *checkCommand) Run(ctx *dep.Ctx, args []string) error {
132136
logger.Println()
133137
}
134138

139+
noverify := make(map[string]bool)
140+
for _, skip := range p.Manifest.NoVerify {
141+
noverify[skip] = true
142+
}
143+
135144
var vendorfail bool
136145
// One full pass through, to see if we need to print the header, and to
137146
// create an array of names to sort for deterministic output.
138147
var ordered []string
139148
for path, status := range statuses {
140149
ordered = append(ordered, path)
141-
if status != verify.NoMismatch {
150+
151+
switch status {
152+
case verify.DigestMismatchInLock, verify.HashVersionMismatch, verify.EmptyDigestInLock:
153+
// NoVerify applies only to these three cases.
154+
if noverify[path] {
155+
continue
156+
}
157+
fallthrough
158+
case verify.NotInTree, verify.NotInLock:
142159
fail = true
143160
if !vendorfail {
144161
vendorfail = true
145162
logger.Println("# vendor is out of sync:")
146163
}
164+
147165
}
148166
}
149167
sort.Strings(ordered)
150168

151169
for _, pr := range ordered {
170+
var nvSuffix string
171+
if noverify[pr] {
172+
nvSuffix = " (CHECK IGNORED: marked noverify in Gopkg.toml)"
173+
}
174+
152175
status := statuses[pr]
153176
switch status {
154177
case verify.NotInTree:
@@ -158,19 +181,20 @@ func (cmd *checkCommand) Run(ctx *dep.Ctx, args []string) error {
158181
if err != nil {
159182
return errors.Wrap(err, "could not stat file that VerifyVendor claimed existed")
160183
}
161-
162184
if fi.IsDir() {
163185
logger.Printf("%s: unused project\n", pr)
164186
} else {
165187
logger.Printf("%s: orphaned file\n", pr)
166188
}
167189
case verify.DigestMismatchInLock:
168-
logger.Printf("%s: hash of vendored tree didn't match digest in Gopkg.lock\n", pr)
190+
logger.Printf("%s: hash of vendored tree not equal to digest in Gopkg.lock%s\n", pr, nvSuffix)
191+
case verify.EmptyDigestInLock:
192+
logger.Printf("%s: no digest in Gopkg.lock to compare against hash of vendored tree%s\n", pr, nvSuffix)
169193
case verify.HashVersionMismatch:
170194
// This will double-print if the hash version is zero, but
171195
// that's a rare case that really only occurs before the first
172196
// run with a version of dep >=0.5.0, so it's fine.
173-
logger.Printf("%s: hash algorithm mismatch, want version %v\n", pr, verify.HashVersion)
197+
logger.Printf("%s: hash algorithm mismatch, want version %v%s\n", pr, verify.HashVersion, nvSuffix)
174198
}
175199
}
176200
}
@@ -185,12 +209,12 @@ func sprintLockUnsat(lsat verify.LockSatisfaction) string {
185209
var buf bytes.Buffer
186210
sort.Strings(lsat.MissingImports)
187211
for _, missing := range lsat.MissingImports {
188-
fmt.Fprintf(&buf, "%s: missing from input-imports\n", missing)
212+
fmt.Fprintf(&buf, "%s: imported or required, but missing from Gopkg.lock's input-imports\n", missing)
189213
}
190214

191215
sort.Strings(lsat.ExcessImports)
192216
for _, excess := range lsat.ExcessImports {
193-
fmt.Fprintf(&buf, "%s: in input-imports, but not imported\n", excess)
217+
fmt.Fprintf(&buf, "%s: in Gopkg.lock's input-imports, but neither imported nor required\n", excess)
194218
}
195219

196220
var ordered []string

cmd/dep/ensure.go

+3-20
Original file line numberDiff line numberDiff line change
@@ -285,11 +285,7 @@ func (cmd *ensureCommand) runDefault(ctx *dep.Ctx, args []string, p *dep.Project
285285
lock = dep.LockFromSolution(solution, p.Manifest.PruneOptions)
286286
}
287287

288-
status, err := p.VerifyVendor()
289-
if err != nil {
290-
return errors.Wrap(err, "error while verifying vendor directory")
291-
}
292-
dw, err := dep.NewDeltaWriter(p.Lock, lock, status, p.Manifest.PruneOptions, filepath.Join(p.AbsRoot, "vendor"), cmd.vendorBehavior())
288+
dw, err := dep.NewDeltaWriter(p, lock, cmd.vendorBehavior())
293289
if err != nil {
294290
return err
295291
}
@@ -365,11 +361,7 @@ func (cmd *ensureCommand) runUpdate(ctx *dep.Ctx, args []string, p *dep.Project,
365361
return handleAllTheFailuresOfTheWorld(err)
366362
}
367363

368-
status, err := p.VerifyVendor()
369-
if err != nil {
370-
return errors.Wrap(err, "error while verifying vendor directory")
371-
}
372-
dw, err := dep.NewDeltaWriter(p.Lock, dep.LockFromSolution(solution, p.Manifest.PruneOptions), status, p.Manifest.PruneOptions, filepath.Join(p.AbsRoot, "vendor"), cmd.vendorBehavior())
364+
dw, err := dep.NewDeltaWriter(p, dep.LockFromSolution(solution, p.Manifest.PruneOptions), cmd.vendorBehavior())
373365
if err != nil {
374366
return err
375367
}
@@ -411,11 +403,6 @@ func (cmd *ensureCommand) runAdd(ctx *dep.Ctx, args []string, p *dep.Project, sm
411403
}
412404
}
413405

414-
//exrmap, err := p.GetDirectDependencyNames(sm)
415-
//if err != nil {
416-
//return err
417-
//}
418-
419406
// Note: these flags are only partially used by the latter parts of the
420407
// algorithm; rather, it relies on inference. However, they remain in their
421408
// entirety as future needs may make further use of them, being a handy,
@@ -643,11 +630,7 @@ func (cmd *ensureCommand) runAdd(ctx *dep.Ctx, args []string, p *dep.Project, sm
643630
}
644631
sort.Strings(reqlist)
645632

646-
status, err := p.VerifyVendor()
647-
if err != nil {
648-
return errors.Wrap(err, "error while verifying vendor directory")
649-
}
650-
dw, err := dep.NewDeltaWriter(p.Lock, dep.LockFromSolution(solution, p.Manifest.PruneOptions), status, p.Manifest.PruneOptions, filepath.Join(p.AbsRoot, "vendor"), cmd.vendorBehavior())
633+
dw, err := dep.NewDeltaWriter(p, dep.LockFromSolution(solution, p.Manifest.PruneOptions), cmd.vendorBehavior())
651634
if err != nil {
652635
return err
653636
}

cmd/dep/integration_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,12 @@ func testIntegration(name, relPath, wd string, run integration.RunFunc) func(t *
195195
}
196196
}
197197

198+
if err != nil {
199+
t.Log(err)
200+
}
201+
198202
// Check error raised in final command
203+
testCase.CompareCmdFailure(err != nil)
199204
testCase.CompareError(err, testProj.GetStderr())
200205

201206
if *test.UpdateGolden {
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Gopkg.lock is out of sync:
2-
github.com/sdboyer/deptest: in input-imports, but not imported
2+
github.com/sdboyer/deptest: in Gopkg.lock's input-imports, but neither imported nor required
33

cmd/dep/testdata/harness_tests/check/excess_inputs/testcase.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
"commands": [
33
["check"]
44
],
5-
"exit-code": 1,
5+
"should-fail": true,
66
"vendor-final": []
77
}
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# vendor is out of sync:
2-
github.com/sdboyer/deptest: hash of vendored tree didn't match digest in Gopkg.lock
2+
github.com/sdboyer/deptest: hash of vendored tree not equal to digest in Gopkg.lock

cmd/dep/testdata/harness_tests/check/hash_mismatch/testcase.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"commands": [
33
["check"]
44
],
5-
"exit-code": 1,
5+
"should-fail": true,
66
"vendor-final": [
77
"github.com/sdboyer/deptest"
88
]

cmd/dep/testdata/harness_tests/check/hash_version_mismatch/testcase.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"commands": [
33
["check"]
44
],
5-
"exit-code": 1,
5+
"should-fail": true,
66
"vendor-final": [
77
"github.com/sdboyer/deptest"
88
]
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# Gopkg.lock is out of sync:
2-
github.com/sdboyer/deptestdos: missing from input-imports
3-
github.com/sdboyer/deptest: in input-imports, but not imported
2+
github.com/sdboyer/deptestdos: imported or required, but missing from Gopkg.lock's input-imports
3+
github.com/sdboyer/deptest: in Gopkg.lock's input-imports, but neither imported nor required
44

cmd/dep/testdata/harness_tests/check/missing_and_excess/testcase.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
"commands": [
33
["check"]
44
],
5-
"exit-code": 1,
5+
"should-fail": true,
66
"vendor-final": []
77
}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Gopkg.lock is out of sync:
2-
github.com/sdboyer/deptestdos: missing from input-imports
2+
github.com/sdboyer/deptestdos: imported or required, but missing from Gopkg.lock's input-imports
33

cmd/dep/testdata/harness_tests/check/missing_inputs/testcase.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
"commands": [
33
["check"]
44
],
5-
"exit-code": 1,
5+
"should-fail": true,
66
"vendor-final": []
77
}

cmd/dep/testdata/harness_tests/check/noverify/hash_mismatch/final/Gopkg.lock

+17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
noverify = ["github.com/sdboyer/deptest"]

cmd/dep/testdata/harness_tests/check/noverify/hash_mismatch/initial/Gopkg.lock

+17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
noverify = ["github.com/sdboyer/deptest"]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright 2017 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package main
6+
7+
import (
8+
_ "github.com/sdboyer/deptest"
9+
)
10+
11+
func main() {
12+
}

cmd/dep/testdata/harness_tests/check/noverify/hash_mismatch/initial/vendor/github.com/sdboyer/deptest/deptest.go

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
github.com/sdboyer/deptest: hash of vendored tree not equal to digest in Gopkg.lock (CHECK IGNORED: marked noverify in Gopkg.toml)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"commands": [
3+
["check"]
4+
],
5+
"vendor-final": [
6+
"github.com/sdboyer/deptest"
7+
]
8+
}

cmd/dep/testdata/harness_tests/check/noverify/hash_version_mismatch/final/Gopkg.lock

+17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
noverify = ["github.com/sdboyer/deptest"]

cmd/dep/testdata/harness_tests/check/noverify/hash_version_mismatch/initial/Gopkg.lock

+17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
noverify = ["github.com/sdboyer/deptest"]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright 2017 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package main
6+
7+
import (
8+
_ "github.com/sdboyer/deptest"
9+
)
10+
11+
func main() {
12+
}

cmd/dep/testdata/harness_tests/check/noverify/hash_version_mismatch/initial/vendor/github.com/sdboyer/deptest/deptest.go

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
github.com/sdboyer/deptest: hash algorithm mismatch, want version 1 (CHECK IGNORED: marked noverify in Gopkg.toml)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"commands": [
3+
["check"]
4+
],
5+
"vendor-final": [
6+
"github.com/sdboyer/deptest"
7+
]
8+
}

cmd/dep/testdata/harness_tests/check/noverify/missing_and_excess/final/Gopkg.lock

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
noverify = ["github.com/sdboyer/deptest"]

cmd/dep/testdata/harness_tests/check/noverify/missing_and_excess/initial/Gopkg.lock

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
noverify = ["github.com/sdboyer/deptest"]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright 2017 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package main
6+
7+
import (
8+
_ "github.com/sdboyer/deptestdos"
9+
)
10+
11+
func main() {
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Gopkg.lock is out of sync:
2+
github.com/sdboyer/deptestdos: imported or required, but missing from Gopkg.lock's input-imports
3+
github.com/sdboyer/deptest: in Gopkg.lock's input-imports, but neither imported nor required
4+

0 commit comments

Comments
 (0)