diff --git a/cmd/dep/ensure.go b/cmd/dep/ensure.go index 60d9c7659e..b90ba975b4 100644 --- a/cmd/dep/ensure.go +++ b/cmd/dep/ensure.go @@ -162,6 +162,10 @@ func (cmd *ensureCommand) Run(ctx *dep.Ctx, args []string) error { params.TraceLogger = ctx.Err } + if cmd.vendorOnly { + return cmd.runVendorOnly(ctx, args, p, sm, params) + } + params.RootPackageTree, err = pkgtree.ListPackages(p.ResolvedAbsRoot, string(p.ImportRoot)) if err != nil { return errors.Wrap(err, "ensure ListPackage for project") @@ -202,31 +206,9 @@ func (cmd *ensureCommand) validateFlags() error { func (cmd *ensureCommand) runDefault(ctx *dep.Ctx, args []string, p *dep.Project, sm gps.SourceManager, params gps.SolveParameters) error { // Bare ensure doesn't take any args. if len(args) != 0 { - if cmd.vendorOnly { - return errors.Errorf("dep ensure -vendor-only only populates vendor/ from %s; it takes no spec arguments", dep.LockName) - } return errors.New("dep ensure only takes spec arguments with -add or -update") } - if cmd.vendorOnly { - if p.Lock == nil { - return errors.Errorf("no %s exists from which to populate vendor/", dep.LockName) - } - // Pass the same lock as old and new so that the writer will observe no - // difference and choose not to write it out. - sw, err := dep.NewSafeWriter(nil, p.Lock, p.Lock, dep.VendorAlways) - if err != nil { - return err - } - - if cmd.dryRun { - ctx.Out.Printf("Would have populated vendor/ directory from %s", dep.LockName) - return nil - } - - return errors.WithMessage(sw.Write(p.AbsRoot, sm, true), "grouped write of manifest, lock and vendor") - } - solver, err := gps.Prepare(params, sm) if err != nil { return errors.Wrap(err, "prepare solver") @@ -279,6 +261,29 @@ func (cmd *ensureCommand) runDefault(ctx *dep.Ctx, args []string, p *dep.Project return errors.Wrap(sw.Write(p.AbsRoot, sm, false), "grouped write of manifest, lock and vendor") } +func (cmd *ensureCommand) runVendorOnly(ctx *dep.Ctx, args []string, p *dep.Project, sm gps.SourceManager, params gps.SolveParameters) error { + if len(args) != 0 { + return errors.Errorf("dep ensure -vendor-only only populates vendor/ from %s; it takes no spec arguments", dep.LockName) + } + + if p.Lock == nil { + return errors.Errorf("no %s exists from which to populate vendor/", dep.LockName) + } + // Pass the same lock as old and new so that the writer will observe no + // difference and choose not to write it out. + sw, err := dep.NewSafeWriter(nil, p.Lock, p.Lock, dep.VendorAlways) + if err != nil { + return err + } + + if cmd.dryRun { + ctx.Out.Printf("Would have populated vendor/ directory from %s", dep.LockName) + return nil + } + + return errors.WithMessage(sw.Write(p.AbsRoot, sm, true), "grouped write of manifest, lock and vendor") +} + func (cmd *ensureCommand) runUpdate(ctx *dep.Ctx, args []string, p *dep.Project, sm gps.SourceManager, params gps.SolveParameters) error { if p.Lock == nil { return errors.Errorf("-update works by updating the versions recorded in %s, but %s does not exist", dep.LockName, dep.LockName) diff --git a/cmd/dep/testdata/harness_tests/ensure/default/nocode-vendoronly/final/Gopkg.lock b/cmd/dep/testdata/harness_tests/ensure/default/nocode-vendoronly/final/Gopkg.lock new file mode 100644 index 0000000000..11cb12c378 --- /dev/null +++ b/cmd/dep/testdata/harness_tests/ensure/default/nocode-vendoronly/final/Gopkg.lock @@ -0,0 +1,16 @@ +# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. + + +[[projects]] + name = "github.com/sdboyer/deptest" + packages = ["."] + revision = "ff2948a2ac8f538c4ecd55962e919d1e13e74baf" + version = "v1.0.0" + +[solve-meta] + analyzer-name = "dep" + analyzer-version = 1 + # manually modified hash digest, it will not match any known inputs + inputs-digest = "94b07b05e0f01051b03887ab2bf80b516bc5510ea92f75f76c894b1745d8850c" + solver-name = "gps-cdcl" + solver-version = 1 diff --git a/cmd/dep/testdata/harness_tests/ensure/default/nocode-vendoronly/final/Gopkg.toml b/cmd/dep/testdata/harness_tests/ensure/default/nocode-vendoronly/final/Gopkg.toml new file mode 100644 index 0000000000..e242e02114 --- /dev/null +++ b/cmd/dep/testdata/harness_tests/ensure/default/nocode-vendoronly/final/Gopkg.toml @@ -0,0 +1,4 @@ + +[[constraint]] + name = "github.com/sdboyer/deptest" + version = "1.0.0" diff --git a/cmd/dep/testdata/harness_tests/ensure/default/nocode-vendoronly/initial/Gopkg.lock b/cmd/dep/testdata/harness_tests/ensure/default/nocode-vendoronly/initial/Gopkg.lock new file mode 100644 index 0000000000..11cb12c378 --- /dev/null +++ b/cmd/dep/testdata/harness_tests/ensure/default/nocode-vendoronly/initial/Gopkg.lock @@ -0,0 +1,16 @@ +# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. + + +[[projects]] + name = "github.com/sdboyer/deptest" + packages = ["."] + revision = "ff2948a2ac8f538c4ecd55962e919d1e13e74baf" + version = "v1.0.0" + +[solve-meta] + analyzer-name = "dep" + analyzer-version = 1 + # manually modified hash digest, it will not match any known inputs + inputs-digest = "94b07b05e0f01051b03887ab2bf80b516bc5510ea92f75f76c894b1745d8850c" + solver-name = "gps-cdcl" + solver-version = 1 diff --git a/cmd/dep/testdata/harness_tests/ensure/default/nocode-vendoronly/initial/Gopkg.toml b/cmd/dep/testdata/harness_tests/ensure/default/nocode-vendoronly/initial/Gopkg.toml new file mode 100644 index 0000000000..e242e02114 --- /dev/null +++ b/cmd/dep/testdata/harness_tests/ensure/default/nocode-vendoronly/initial/Gopkg.toml @@ -0,0 +1,4 @@ + +[[constraint]] + name = "github.com/sdboyer/deptest" + version = "1.0.0" diff --git a/cmd/dep/testdata/harness_tests/ensure/default/nocode-vendoronly/testcase.json b/cmd/dep/testdata/harness_tests/ensure/default/nocode-vendoronly/testcase.json new file mode 100644 index 0000000000..8a28875978 --- /dev/null +++ b/cmd/dep/testdata/harness_tests/ensure/default/nocode-vendoronly/testcase.json @@ -0,0 +1,8 @@ +{ + "commands": [ + ["ensure", "-vendor-only"] + ], + "vendor-final": [ + "github.com/sdboyer/deptest" + ] +}