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

Commit

Permalink
Merge pull request #954 from ebati/ensure-without-go-code
Browse files Browse the repository at this point in the history
Ensure without go code
  • Loading branch information
sdboyer authored Aug 5, 2017
2 parents ea735f9 + 0fe56b2 commit 4455eff
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 22 deletions.
49 changes: 27 additions & 22 deletions cmd/dep/ensure.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

[[constraint]]
name = "github.com/sdboyer/deptest"
version = "1.0.0"

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

[[constraint]]
name = "github.com/sdboyer/deptest"
version = "1.0.0"
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"commands": [
["ensure", "-vendor-only"]
],
"vendor-final": [
"github.com/sdboyer/deptest"
]
}

0 comments on commit 4455eff

Please sign in to comment.