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

Commit 4455eff

Browse files
authoredAug 5, 2017
Merge pull request #954 from ebati/ensure-without-go-code
Ensure without go code
2 parents ea735f9 + 0fe56b2 commit 4455eff

File tree

6 files changed

+75
-22
lines changed

6 files changed

+75
-22
lines changed
 

‎cmd/dep/ensure.go

+27-22
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,10 @@ func (cmd *ensureCommand) Run(ctx *dep.Ctx, args []string) error {
162162
params.TraceLogger = ctx.Err
163163
}
164164

165+
if cmd.vendorOnly {
166+
return cmd.runVendorOnly(ctx, args, p, sm, params)
167+
}
168+
165169
params.RootPackageTree, err = pkgtree.ListPackages(p.ResolvedAbsRoot, string(p.ImportRoot))
166170
if err != nil {
167171
return errors.Wrap(err, "ensure ListPackage for project")
@@ -202,31 +206,9 @@ func (cmd *ensureCommand) validateFlags() error {
202206
func (cmd *ensureCommand) runDefault(ctx *dep.Ctx, args []string, p *dep.Project, sm gps.SourceManager, params gps.SolveParameters) error {
203207
// Bare ensure doesn't take any args.
204208
if len(args) != 0 {
205-
if cmd.vendorOnly {
206-
return errors.Errorf("dep ensure -vendor-only only populates vendor/ from %s; it takes no spec arguments", dep.LockName)
207-
}
208209
return errors.New("dep ensure only takes spec arguments with -add or -update")
209210
}
210211

211-
if cmd.vendorOnly {
212-
if p.Lock == nil {
213-
return errors.Errorf("no %s exists from which to populate vendor/", dep.LockName)
214-
}
215-
// Pass the same lock as old and new so that the writer will observe no
216-
// difference and choose not to write it out.
217-
sw, err := dep.NewSafeWriter(nil, p.Lock, p.Lock, dep.VendorAlways)
218-
if err != nil {
219-
return err
220-
}
221-
222-
if cmd.dryRun {
223-
ctx.Out.Printf("Would have populated vendor/ directory from %s", dep.LockName)
224-
return nil
225-
}
226-
227-
return errors.WithMessage(sw.Write(p.AbsRoot, sm, true), "grouped write of manifest, lock and vendor")
228-
}
229-
230212
solver, err := gps.Prepare(params, sm)
231213
if err != nil {
232214
return errors.Wrap(err, "prepare solver")
@@ -279,6 +261,29 @@ func (cmd *ensureCommand) runDefault(ctx *dep.Ctx, args []string, p *dep.Project
279261
return errors.Wrap(sw.Write(p.AbsRoot, sm, false), "grouped write of manifest, lock and vendor")
280262
}
281263

264+
func (cmd *ensureCommand) runVendorOnly(ctx *dep.Ctx, args []string, p *dep.Project, sm gps.SourceManager, params gps.SolveParameters) error {
265+
if len(args) != 0 {
266+
return errors.Errorf("dep ensure -vendor-only only populates vendor/ from %s; it takes no spec arguments", dep.LockName)
267+
}
268+
269+
if p.Lock == nil {
270+
return errors.Errorf("no %s exists from which to populate vendor/", dep.LockName)
271+
}
272+
// Pass the same lock as old and new so that the writer will observe no
273+
// difference and choose not to write it out.
274+
sw, err := dep.NewSafeWriter(nil, p.Lock, p.Lock, dep.VendorAlways)
275+
if err != nil {
276+
return err
277+
}
278+
279+
if cmd.dryRun {
280+
ctx.Out.Printf("Would have populated vendor/ directory from %s", dep.LockName)
281+
return nil
282+
}
283+
284+
return errors.WithMessage(sw.Write(p.AbsRoot, sm, true), "grouped write of manifest, lock and vendor")
285+
}
286+
282287
func (cmd *ensureCommand) runUpdate(ctx *dep.Ctx, args []string, p *dep.Project, sm gps.SourceManager, params gps.SolveParameters) error {
283288
if p.Lock == nil {
284289
return errors.Errorf("-update works by updating the versions recorded in %s, but %s does not exist", dep.LockName, dep.LockName)

‎cmd/dep/testdata/harness_tests/ensure/default/nocode-vendoronly/final/Gopkg.lock

+16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
[[constraint]]
3+
name = "github.com/sdboyer/deptest"
4+
version = "1.0.0"

‎cmd/dep/testdata/harness_tests/ensure/default/nocode-vendoronly/initial/Gopkg.lock

+16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
[[constraint]]
3+
name = "github.com/sdboyer/deptest"
4+
version = "1.0.0"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"commands": [
3+
["ensure", "-vendor-only"]
4+
],
5+
"vendor-final": [
6+
"github.com/sdboyer/deptest"
7+
]
8+
}

0 commit comments

Comments
 (0)
This repository has been archived.