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

Commit 3c04147

Browse files
authored
Merge pull request #2002 from sdboyer/noverify-preserve-files
dep: Make noverify preserve excess vendor paths
2 parents 3807092 + 8a9bd79 commit 3c04147

File tree

17 files changed

+151
-45
lines changed

17 files changed

+151
-45
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# v0.5.1
22

3+
IMPROVEMENTS:
4+
5+
* The `noverify` field in `Gopkg.toml` allows for the preservation of excess files under `vendor`. ([#2002](https://github.com/golang/dep/issue/2002))
6+
37
BUG FIXES:
48

59
* Correctly handle certain cases where `dep ensure` removed projects from Gopkg.lock. ([#1945](https://github.com/golang/dep/issue/1945)).

cmd/dep/check.go

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -141,62 +141,83 @@ func (cmd *checkCommand) Run(ctx *dep.Ctx, args []string) error {
141141
noverify[skip] = true
142142
}
143143

144-
var vendorfail bool
144+
var vendorfail, hasnoverify bool
145145
// One full pass through, to see if we need to print the header, and to
146146
// create an array of names to sort for deterministic output.
147147
var ordered []string
148148
for path, status := range statuses {
149149
ordered = append(ordered, path)
150150

151151
switch status {
152-
case verify.DigestMismatchInLock, verify.HashVersionMismatch, verify.EmptyDigestInLock:
153-
// NoVerify applies only to these three cases.
152+
case verify.DigestMismatchInLock, verify.HashVersionMismatch, verify.EmptyDigestInLock, verify.NotInLock:
154153
if noverify[path] {
154+
hasnoverify = true
155155
continue
156156
}
157157
fallthrough
158-
case verify.NotInTree, verify.NotInLock:
158+
case verify.NotInTree:
159+
// NoVerify cannot be used to make dep check ignore the absence
160+
// of a project entirely.
161+
if noverify[path] {
162+
delete(noverify, path)
163+
}
164+
159165
fail = true
160166
if !vendorfail {
161167
vendorfail = true
162-
logger.Println("# vendor is out of sync:")
163168
}
164-
165169
}
166170
}
167171
sort.Strings(ordered)
168172

173+
var vfbuf, novbuf bytes.Buffer
174+
var bufptr *bytes.Buffer
175+
176+
fmt.Fprintf(&vfbuf, "# vendor is out of sync:\n")
177+
fmt.Fprintf(&novbuf, "# out of sync, but ignored, due to noverify in Gopkg.toml:\n")
178+
169179
for _, pr := range ordered {
170-
var nvSuffix string
171180
if noverify[pr] {
172-
nvSuffix = " (CHECK IGNORED: marked noverify in Gopkg.toml)"
181+
bufptr = &novbuf
182+
} else {
183+
bufptr = &vfbuf
173184
}
174185

175186
status := statuses[pr]
176187
switch status {
177188
case verify.NotInTree:
178-
logger.Printf("%s: missing from vendor\n", pr)
189+
fmt.Fprintf(bufptr, "%s: missing from vendor\n", pr)
179190
case verify.NotInLock:
180191
fi, err := os.Stat(filepath.Join(p.AbsRoot, "vendor", pr))
181192
if err != nil {
182193
return errors.Wrap(err, "could not stat file that VerifyVendor claimed existed")
183194
}
184195
if fi.IsDir() {
185-
logger.Printf("%s: unused project\n", pr)
196+
fmt.Fprintf(bufptr, "%s: unused project\n", pr)
186197
} else {
187-
logger.Printf("%s: orphaned file\n", pr)
198+
fmt.Fprintf(bufptr, "%s: orphaned file\n", pr)
188199
}
189200
case verify.DigestMismatchInLock:
190-
logger.Printf("%s: hash of vendored tree not equal to digest in Gopkg.lock%s\n", pr, nvSuffix)
201+
fmt.Fprintf(bufptr, "%s: hash of vendored tree not equal to digest in Gopkg.lock\n", pr)
191202
case verify.EmptyDigestInLock:
192-
logger.Printf("%s: no digest in Gopkg.lock to compare against hash of vendored tree%s\n", pr, nvSuffix)
203+
fmt.Fprintf(bufptr, "%s: no digest in Gopkg.lock to compare against hash of vendored tree\n", pr)
193204
case verify.HashVersionMismatch:
194205
// This will double-print if the hash version is zero, but
195206
// that's a rare case that really only occurs before the first
196207
// run with a version of dep >=0.5.0, so it's fine.
197-
logger.Printf("%s: hash algorithm mismatch, want version %v%s\n", pr, verify.HashVersion, nvSuffix)
208+
fmt.Fprintf(bufptr, "%s: hash algorithm mismatch, want version %v\n", pr, verify.HashVersion)
198209
}
199210
}
211+
212+
if vendorfail {
213+
logger.Print(vfbuf.String())
214+
if hasnoverify {
215+
logger.Println()
216+
}
217+
}
218+
if hasnoverify {
219+
logger.Print(novbuf.String())
220+
}
200221
}
201222

202223
if fail {
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
github.com/sdboyer/deptest: hash of vendored tree not equal to digest in Gopkg.lock (CHECK IGNORED: marked noverify in Gopkg.toml)
1+
# out of sync, but ignored, due to noverify in Gopkg.toml:
2+
github.com/sdboyer/deptest: hash of vendored tree not equal to digest in Gopkg.lock
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
github.com/sdboyer/deptest: hash algorithm mismatch, want version 1 (CHECK IGNORED: marked noverify in Gopkg.toml)
1+
# out of sync, but ignored, due to noverify in Gopkg.toml:
2+
github.com/sdboyer/deptest: hash algorithm mismatch, want version 1

cmd/dep/testdata/harness_tests/ensure/noverify/hash_mismatch/README

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ This is a hack - it's effectively just verifying that the Gopkg.lock doesn't
22
change for projects with noverify set, which (under the current logic) is an
33
indicator that vendor wasn't updated.
44

5-
Of course, that vendor -> lock relatinoship isn't guaranteed to hold...
5+
Of course, that vendor -> lock relationship isn't guaranteed to hold...

cmd/dep/testdata/harness_tests/ensure/noverify/vendororphans/final/Gopkg.lock

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
noverify = ["foo", "orphdir"]

cmd/dep/testdata/harness_tests/ensure/noverify/vendororphans/initial/Gopkg.lock

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
noverify = ["foo", "orphdir"]
Lines changed: 12 additions & 0 deletions
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+
}

0 commit comments

Comments
 (0)