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

Commit d895a66

Browse files
jmank88ibrasho
authored andcommitted
ensure: tweaks to align no-vendor behavior and verbose/dry-run logging (#1039)
* ensure: tweaks to align no-vendor behavior and verbose/dry-run logging * ensure: dry-run: always log lock diff * log PrintPreparedActions to ctx Out not Err
1 parent 1bef80e commit d895a66

File tree

2 files changed

+38
-32
lines changed

2 files changed

+38
-32
lines changed

Diff for: cmd/dep/ensure.go

+14-18
Original file line numberDiff line numberDiff line change
@@ -223,15 +223,15 @@ func (cmd *ensureCommand) runDefault(ctx *dep.Ctx, args []string, p *dep.Project
223223

224224
if p.Lock != nil && bytes.Equal(p.Lock.InputHash(), solver.HashInputs()) {
225225
// Memo matches, so there's probably nothing to do.
226+
if ctx.Verbose {
227+
ctx.Out.Printf("%s was already in sync with imports and %s\n", dep.LockName, dep.ManifestName)
228+
}
229+
226230
if cmd.noVendor {
227231
// The user said not to touch vendor/, so definitely nothing to do.
228232
return nil
229233
}
230234

231-
if ctx.Verbose {
232-
ctx.Out.Printf("%s was already in sync with imports and %s, recreating vendor/ directory", dep.LockName, dep.ManifestName)
233-
}
234-
235235
// TODO(sdboyer) The desired behavior at this point is to determine
236236
// whether it's necessary to write out vendor, or if it's already
237237
// consistent with the lock. However, we haven't yet determined what
@@ -244,8 +244,7 @@ func (cmd *ensureCommand) runDefault(ctx *dep.Ctx, args []string, p *dep.Project
244244
}
245245

246246
if cmd.dryRun {
247-
ctx.Out.Printf("Would have populated vendor/ directory from %s", dep.LockName)
248-
return nil
247+
return sw.PrintPreparedActions(ctx.Out, ctx.Verbose)
249248
}
250249

251250
logger := ctx.Err
@@ -261,12 +260,16 @@ func (cmd *ensureCommand) runDefault(ctx *dep.Ctx, args []string, p *dep.Project
261260
return errors.Wrap(err, "ensure Solve()")
262261
}
263262

264-
sw, err := dep.NewSafeWriter(nil, p.Lock, dep.LockFromSolution(solution), dep.VendorOnChanged)
263+
vendorBehavior := dep.VendorOnChanged
264+
if cmd.noVendor {
265+
vendorBehavior = dep.VendorNever
266+
}
267+
sw, err := dep.NewSafeWriter(nil, p.Lock, dep.LockFromSolution(solution), vendorBehavior)
265268
if err != nil {
266269
return err
267270
}
268271
if cmd.dryRun {
269-
return sw.PrintPreparedActions(ctx.Out)
272+
return sw.PrintPreparedActions(ctx.Out, ctx.Verbose)
270273
}
271274

272275
logger := ctx.Err
@@ -292,14 +295,7 @@ func (cmd *ensureCommand) runVendorOnly(ctx *dep.Ctx, args []string, p *dep.Proj
292295
}
293296

294297
if cmd.dryRun {
295-
ctx.Out.Printf("Would have populated vendor/ directory from %s", dep.LockName)
296-
if ctx.Verbose {
297-
err := sw.PrintPreparedActions(ctx.Err)
298-
if err != nil {
299-
return errors.WithMessage(err, "prepared actions")
300-
}
301-
}
302-
return nil
298+
return sw.PrintPreparedActions(ctx.Out, ctx.Verbose)
303299
}
304300

305301
logger := ctx.Err
@@ -394,7 +390,7 @@ func (cmd *ensureCommand) runUpdate(ctx *dep.Ctx, args []string, p *dep.Project,
394390
return err
395391
}
396392
if cmd.dryRun {
397-
return sw.PrintPreparedActions(ctx.Out)
393+
return sw.PrintPreparedActions(ctx.Out, ctx.Verbose)
398394
}
399395

400396
logger := ctx.Err
@@ -648,7 +644,7 @@ func (cmd *ensureCommand) runAdd(ctx *dep.Ctx, args []string, p *dep.Project, sm
648644
}
649645

650646
if cmd.dryRun {
651-
return sw.PrintPreparedActions(ctx.Out)
647+
return sw.PrintPreparedActions(ctx.Out, ctx.Verbose)
652648
}
653649

654650
logger := ctx.Err

Diff for: txn_writer.go

+24-14
Original file line numberDiff line numberDiff line change
@@ -418,24 +418,30 @@ fail:
418418
}
419419

420420
// PrintPreparedActions logs the actions a call to Write would perform.
421-
func (sw *SafeWriter) PrintPreparedActions(output *log.Logger) error {
421+
func (sw *SafeWriter) PrintPreparedActions(output *log.Logger, verbose bool) error {
422422
if sw.HasManifest() {
423-
output.Printf("Would have written the following %s:\n", ManifestName)
424-
m, err := sw.Manifest.MarshalTOML()
425-
if err != nil {
426-
return errors.Wrap(err, "ensure DryRun cannot serialize manifest")
423+
if verbose {
424+
m, err := sw.Manifest.MarshalTOML()
425+
if err != nil {
426+
return errors.Wrap(err, "ensure DryRun cannot serialize manifest")
427+
}
428+
output.Printf("Would have written the following %s:\n%s\n", ManifestName, string(m))
429+
} else {
430+
output.Printf("Would have written %s.\n", ManifestName)
427431
}
428-
output.Println(string(m))
429432
}
430433

431434
if sw.writeLock {
432435
if sw.lockDiff == nil {
433-
output.Printf("Would have written the following %s:\n", LockName)
434-
l, err := sw.lock.MarshalTOML()
435-
if err != nil {
436-
return errors.Wrap(err, "ensure DryRun cannot serialize lock")
436+
if verbose {
437+
l, err := sw.lock.MarshalTOML()
438+
if err != nil {
439+
return errors.Wrap(err, "ensure DryRun cannot serialize lock")
440+
}
441+
output.Printf("Would have written the following %s:\n%s\n", LockName, string(l))
442+
} else {
443+
output.Printf("Would have written %s.\n", LockName)
437444
}
438-
output.Println(string(l))
439445
} else {
440446
output.Printf("Would have written the following changes to %s:\n", LockName)
441447
diff, err := formatLockDiff(*sw.lockDiff)
@@ -447,9 +453,13 @@ func (sw *SafeWriter) PrintPreparedActions(output *log.Logger) error {
447453
}
448454

449455
if sw.writeVendor {
450-
output.Println("Would have written the following projects to the vendor directory:")
451-
for _, project := range sw.lock.Projects() {
452-
output.Println(project)
456+
if verbose {
457+
output.Printf("Would have written the following %d projects to the vendor directory:\n", len(sw.lock.Projects()))
458+
for _, project := range sw.lock.Projects() {
459+
output.Println(project)
460+
}
461+
} else {
462+
output.Printf("Would have written %d projects to the vendor directory.\n", len(sw.lock.Projects()))
453463
}
454464
}
455465

0 commit comments

Comments
 (0)