Skip to content

Commit

Permalink
ensure: always write vendor even if not empty
Browse files Browse the repository at this point in the history
If the vendor directory already exists, and the lock file hasn't
changed, even though a project may be missing from the vendor
directory, dep ensure would not add the dependency to the vendor
folder.

If the project is in the vendor folder, but it has been modified
(no longer in sync with lock file), ensure would not replace the
dependency in the vendor folder.

This change causes dep ensure to run anytime there's a solution,
regardless of the state vendor folder is in, erring on the side
of replacing vendor without checking existing state which is the
most correct behaviour given the ensure intention.

Future optimisations may want to check and verify the contents of
the vendor folder before blinding replacing it.

Fixes golang#883.
  • Loading branch information
bradleyfalzon committed Jul 24, 2017
1 parent 167adc2 commit 9bafc5f
Showing 1 changed file with 1 addition and 9 deletions.
10 changes: 1 addition & 9 deletions cmd/dep/ensure.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ import (
"fmt"
"go/build"
"log"
"path/filepath"
"strings"

"github.com/golang/dep"
"github.com/golang/dep/internal/fs"
"github.com/golang/dep/internal/gps"
"github.com/golang/dep/internal/gps/pkgtree"
"github.com/pkg/errors"
Expand Down Expand Up @@ -151,14 +149,8 @@ func (cmd *ensureCommand) Run(ctx *dep.Ctx, args []string) error {
return errors.Wrap(err, "ensure Solve()")
}

// check if vendor exists, because if the locks are the same but
// vendor does not exist we should write vendor
vendorExists, err := fs.IsNonEmptyDir(filepath.Join(p.AbsRoot, "vendor"))
if err != nil {
return errors.Wrap(err, "ensure vendor is a directory")
}
writeV := dep.VendorOnChanged
if !vendorExists && solution != nil {
if solution != nil {
writeV = dep.VendorAlways
}

Expand Down

0 comments on commit 9bafc5f

Please sign in to comment.