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

Commit 683164a

Browse files
committed
check: Deterministically order all output
1 parent dd5c305 commit 683164a

File tree

2 files changed

+44
-9
lines changed

2 files changed

+44
-9
lines changed

cmd/dep/check.go

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"log"
1313
"os"
1414
"path/filepath"
15+
"sort"
1516
"strings"
1617

1718
"github.com/golang/dep"
@@ -89,7 +90,15 @@ func (cmd *checkCommand) Run(ctx *dep.Ctx, args []string) error {
8990
logger.Printf("%s\n", sprintLockUnsat(lsat))
9091
}
9192
if changed {
92-
for pr, lpd := range delta.ProjectDeltas {
93+
// Sort, for deterministic output.
94+
var ordered []string
95+
for pr := range delta.ProjectDeltas {
96+
ordered = append(ordered, string(pr))
97+
}
98+
sort.Strings(ordered)
99+
100+
for _, pr := range ordered {
101+
lpd := delta.ProjectDeltas[gps.ProjectRoot(pr)]
93102
// Only two possible changes right now are prune opts
94103
// changing or a missing hash digest (for old Gopkg.lock
95104
// files)
@@ -122,16 +131,25 @@ func (cmd *checkCommand) Run(ctx *dep.Ctx, args []string) error {
122131
if fail {
123132
logger.Println()
124133
}
125-
// One full pass through, to see if we need to print the header.
126-
for _, status := range statuses {
134+
135+
var vendorfail bool
136+
// One full pass through, to see if we need to print the header, and to
137+
// create an array of names to sort for deterministic output.
138+
var ordered []string
139+
for path, status := range statuses {
140+
ordered = append(ordered, path)
127141
if status != verify.NoMismatch {
128142
fail = true
129-
logger.Println("# vendor is out of sync:")
130-
break
143+
if !vendorfail {
144+
vendorfail = true
145+
logger.Println("# vendor is out of sync:")
146+
}
131147
}
132148
}
149+
sort.Strings(ordered)
133150

134-
for pr, status := range statuses {
151+
for _, pr := range ordered {
152+
status := statuses[pr]
135153
switch status {
136154
case verify.NotInTree:
137155
logger.Printf("%s: missing from vendor\n", pr)
@@ -165,16 +183,33 @@ func (cmd *checkCommand) Run(ctx *dep.Ctx, args []string) error {
165183

166184
func sprintLockUnsat(lsat verify.LockSatisfaction) string {
167185
var buf bytes.Buffer
186+
sort.Strings(lsat.MissingImports)
168187
for _, missing := range lsat.MissingImports {
169188
fmt.Fprintf(&buf, "%s: missing from input-imports\n", missing)
170189
}
190+
191+
sort.Strings(lsat.ExcessImports)
171192
for _, excess := range lsat.ExcessImports {
172193
fmt.Fprintf(&buf, "%s: in input-imports, but not imported\n", excess)
173194
}
174-
for pr, unmatched := range lsat.UnmetOverrides {
195+
196+
var ordered []string
197+
for pr := range lsat.UnmetOverrides {
198+
ordered = append(ordered, string(pr))
199+
}
200+
sort.Strings(ordered)
201+
for _, pr := range ordered {
202+
unmatched := lsat.UnmetOverrides[gps.ProjectRoot(pr)]
175203
fmt.Fprintf(&buf, "%s@%s: not allowed by override %s\n", pr, unmatched.V, unmatched.C)
176204
}
177-
for pr, unmatched := range lsat.UnmetConstraints {
205+
206+
ordered = ordered[:0]
207+
for pr := range lsat.UnmetConstraints {
208+
ordered = append(ordered, string(pr))
209+
}
210+
sort.Strings(ordered)
211+
for _, pr := range ordered {
212+
unmatched := lsat.UnmetConstraints[gps.ProjectRoot(pr)]
178213
fmt.Fprintf(&buf, "%s@%s: not allowed by constraint %s\n", pr, unmatched.V, unmatched.C)
179214
}
180215
return strings.TrimSpace(buf.String())
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# vendor is out of sync:
2-
orphdir: unused project
32
foo: orphaned file
3+
orphdir: unused project

0 commit comments

Comments
 (0)