diff --git a/cmd/dep/ensure.go b/cmd/dep/ensure.go index d646fd361b..06fbd02118 100644 --- a/cmd/dep/ensure.go +++ b/cmd/dep/ensure.go @@ -223,15 +223,15 @@ func (cmd *ensureCommand) runDefault(ctx *dep.Ctx, args []string, p *dep.Project if p.Lock != nil && bytes.Equal(p.Lock.InputHash(), solver.HashInputs()) { // Memo matches, so there's probably nothing to do. + if ctx.Verbose { + ctx.Out.Printf("%s was already in sync with imports and %s\n", dep.LockName, dep.ManifestName) + } + if cmd.noVendor { // The user said not to touch vendor/, so definitely nothing to do. return nil } - if ctx.Verbose { - ctx.Out.Printf("%s was already in sync with imports and %s, recreating vendor/ directory", dep.LockName, dep.ManifestName) - } - // TODO(sdboyer) The desired behavior at this point is to determine // whether it's necessary to write out vendor, or if it's already // 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 } if cmd.dryRun { - ctx.Out.Printf("Would have populated vendor/ directory from %s", dep.LockName) - return nil + return sw.PrintPreparedActions(ctx.Out, ctx.Verbose) } logger := ctx.Err @@ -261,12 +260,16 @@ func (cmd *ensureCommand) runDefault(ctx *dep.Ctx, args []string, p *dep.Project return errors.Wrap(err, "ensure Solve()") } - sw, err := dep.NewSafeWriter(nil, p.Lock, dep.LockFromSolution(solution), dep.VendorOnChanged) + vendorBehavior := dep.VendorOnChanged + if cmd.noVendor { + vendorBehavior = dep.VendorNever + } + sw, err := dep.NewSafeWriter(nil, p.Lock, dep.LockFromSolution(solution), vendorBehavior) if err != nil { return err } if cmd.dryRun { - return sw.PrintPreparedActions(ctx.Out) + return sw.PrintPreparedActions(ctx.Out, ctx.Verbose) } logger := ctx.Err @@ -292,14 +295,7 @@ func (cmd *ensureCommand) runVendorOnly(ctx *dep.Ctx, args []string, p *dep.Proj } if cmd.dryRun { - ctx.Out.Printf("Would have populated vendor/ directory from %s", dep.LockName) - if ctx.Verbose { - err := sw.PrintPreparedActions(ctx.Err) - if err != nil { - return errors.WithMessage(err, "prepared actions") - } - } - return nil + return sw.PrintPreparedActions(ctx.Out, ctx.Verbose) } logger := ctx.Err @@ -394,7 +390,7 @@ func (cmd *ensureCommand) runUpdate(ctx *dep.Ctx, args []string, p *dep.Project, return err } if cmd.dryRun { - return sw.PrintPreparedActions(ctx.Out) + return sw.PrintPreparedActions(ctx.Out, ctx.Verbose) } logger := ctx.Err @@ -648,7 +644,7 @@ func (cmd *ensureCommand) runAdd(ctx *dep.Ctx, args []string, p *dep.Project, sm } if cmd.dryRun { - return sw.PrintPreparedActions(ctx.Out) + return sw.PrintPreparedActions(ctx.Out, ctx.Verbose) } logger := ctx.Err diff --git a/txn_writer.go b/txn_writer.go index 8327c9d7db..224e3eb52b 100644 --- a/txn_writer.go +++ b/txn_writer.go @@ -418,24 +418,30 @@ fail: } // PrintPreparedActions logs the actions a call to Write would perform. -func (sw *SafeWriter) PrintPreparedActions(output *log.Logger) error { +func (sw *SafeWriter) PrintPreparedActions(output *log.Logger, verbose bool) error { if sw.HasManifest() { - output.Printf("Would have written the following %s:\n", ManifestName) - m, err := sw.Manifest.MarshalTOML() - if err != nil { - return errors.Wrap(err, "ensure DryRun cannot serialize manifest") + if verbose { + m, err := sw.Manifest.MarshalTOML() + if err != nil { + return errors.Wrap(err, "ensure DryRun cannot serialize manifest") + } + output.Printf("Would have written the following %s:\n%s\n", ManifestName, string(m)) + } else { + output.Printf("Would have written %s.\n", ManifestName) } - output.Println(string(m)) } if sw.writeLock { if sw.lockDiff == nil { - output.Printf("Would have written the following %s:\n", LockName) - l, err := sw.lock.MarshalTOML() - if err != nil { - return errors.Wrap(err, "ensure DryRun cannot serialize lock") + if verbose { + l, err := sw.lock.MarshalTOML() + if err != nil { + return errors.Wrap(err, "ensure DryRun cannot serialize lock") + } + output.Printf("Would have written the following %s:\n%s\n", LockName, string(l)) + } else { + output.Printf("Would have written %s.\n", LockName) } - output.Println(string(l)) } else { output.Printf("Would have written the following changes to %s:\n", LockName) diff, err := formatLockDiff(*sw.lockDiff) @@ -447,9 +453,13 @@ func (sw *SafeWriter) PrintPreparedActions(output *log.Logger) error { } if sw.writeVendor { - output.Println("Would have written the following projects to the vendor directory:") - for _, project := range sw.lock.Projects() { - output.Println(project) + if verbose { + output.Printf("Would have written the following %d projects to the vendor directory:\n", len(sw.lock.Projects())) + for _, project := range sw.lock.Projects() { + output.Println(project) + } + } else { + output.Printf("Would have written %d projects to the vendor directory.\n", len(sw.lock.Projects())) } }