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

Commit 231ebf2

Browse files
authored
Merge pull request #611 from darkowlzz/161-status-memo-mismatch-feedback
Add status feedback on memo mismatch
2 parents 455cd08 + 6079300 commit 231ebf2

File tree

1 file changed

+27
-10
lines changed

1 file changed

+27
-10
lines changed

cmd/dep/status.go

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -215,11 +215,24 @@ func (cmd *statusCommand) Run(ctx *dep.Ctx, args []string) error {
215215
}
216216
}
217217

218-
if err := runStatusAll(ctx.Loggers, out, p, sm); err != nil {
218+
digestMismatch, hasMissingPkgs, err := runStatusAll(ctx.Loggers, out, p, sm)
219+
if err != nil {
219220
return err
220221
}
221222

222-
ctx.Loggers.Out.Print(buf.String())
223+
if digestMismatch {
224+
if hasMissingPkgs {
225+
ctx.Loggers.Err.Println("Lock inputs-digest mismatch due to the following packages missing from the lock:\n")
226+
ctx.Loggers.Out.Print(buf.String())
227+
ctx.Loggers.Err.Println("\nThis happens when a new import is added. Run `dep ensure` to install the missing packages.")
228+
} else {
229+
ctx.Loggers.Err.Printf("Lock inputs-digest mismatch. This happens when Gopkg.toml is modified.\n" +
230+
"Run `dep ensure` to regenerate the inputs-digest.")
231+
}
232+
} else {
233+
ctx.Loggers.Out.Print(buf.String())
234+
}
235+
223236
return nil
224237
}
225238

@@ -240,17 +253,19 @@ type MissingStatus struct {
240253
MissingPackages []string
241254
}
242255

243-
func runStatusAll(loggers *dep.Loggers, out outputter, p *dep.Project, sm gps.SourceManager) error {
256+
func runStatusAll(loggers *dep.Loggers, out outputter, p *dep.Project, sm gps.SourceManager) (bool, bool, error) {
257+
var digestMismatch, hasMissingPkgs bool
258+
244259
if p.Lock == nil {
245260
// TODO if we have no lock file, do...other stuff
246-
return nil
261+
return digestMismatch, hasMissingPkgs, nil
247262
}
248263

249264
// While the network churns on ListVersions() requests, statically analyze
250265
// code from the current project.
251266
ptree, err := pkgtree.ListPackages(p.AbsRoot, string(p.ImportRoot))
252267
if err != nil {
253-
return errors.Errorf("analysis of local packages failed: %v", err)
268+
return digestMismatch, hasMissingPkgs, errors.Errorf("analysis of local packages failed: %v", err)
254269
}
255270

256271
// Set up a solver in order to check the InputHash.
@@ -267,7 +282,7 @@ func runStatusAll(loggers *dep.Loggers, out outputter, p *dep.Project, sm gps.So
267282

268283
s, err := gps.Prepare(params, sm)
269284
if err != nil {
270-
return errors.Errorf("could not set up solver for input hashing: %s", err)
285+
return digestMismatch, hasMissingPkgs, errors.Errorf("could not set up solver for input hashing: %s", err)
271286
}
272287

273288
cm := collectConstraints(ptree, p, sm)
@@ -298,7 +313,7 @@ func runStatusAll(loggers *dep.Loggers, out outputter, p *dep.Project, sm gps.So
298313
ptr, err := sm.ListPackages(proj.Ident(), proj.Version())
299314

300315
if err != nil {
301-
return fmt.Errorf("analysis of %s package failed: %v", proj.Ident().ProjectRoot, err)
316+
return digestMismatch, hasMissingPkgs, fmt.Errorf("analysis of %s package failed: %v", proj.Ident().ProjectRoot, err)
302317
}
303318

304319
prm, _ := ptr.ToReachMap(true, false, false, nil)
@@ -360,7 +375,7 @@ func runStatusAll(loggers *dep.Loggers, out outputter, p *dep.Project, sm gps.So
360375
}
361376
out.BasicFooter()
362377

363-
return nil
378+
return digestMismatch, hasMissingPkgs, nil
364379
}
365380

366381
// Hash digest mismatch may indicate that some deps are no longer
@@ -369,6 +384,7 @@ func runStatusAll(loggers *dep.Loggers, out outputter, p *dep.Project, sm gps.So
369384
//
370385
// It's possible for digests to not match, but still have a correct
371386
// lock.
387+
digestMismatch = true
372388
rm, _ := ptree.ToReachMap(true, true, false, nil)
373389

374390
external := rm.FlattenFn(paths.IsStandardImportPath)
@@ -401,7 +417,7 @@ func runStatusAll(loggers *dep.Loggers, out outputter, p *dep.Project, sm gps.So
401417
loggers.Err.Printf("\t%s: %s\n", fail.ex, fail.err.Error())
402418
}
403419

404-
return errors.New("address issues with undeducable import paths to get more status information.")
420+
return digestMismatch, hasMissingPkgs, errors.New("address issues with undeducible import paths to get more status information")
405421
}
406422

407423
out.MissingHeader()
@@ -416,11 +432,12 @@ outer:
416432
}
417433
}
418434

435+
hasMissingPkgs = true
419436
out.MissingLine(&MissingStatus{ProjectRoot: string(root), MissingPackages: pkgs})
420437
}
421438
out.MissingFooter()
422439

423-
return nil
440+
return digestMismatch, hasMissingPkgs, nil
424441
}
425442

426443
func formatVersion(v gps.Version) string {

0 commit comments

Comments
 (0)