Added installer pass on for packages found in vendor
This allows packages to be updated that are already present
diff --git a/dependency/resolver.go b/dependency/resolver.go
index 3d0e623..b021836 100644
--- a/dependency/resolver.go
+++ b/dependency/resolver.go
@@ -44,6 +44,11 @@
// An error indicates that OnGopath cannot complete its intended operation.
// Not all false results are errors.
OnGopath(pkg string) (bool, error)
+
+ // InVendor is called when the Resolver finds a dependency in the vendor/ directory.
+ //
+ // This can be used update a project found in the vendor/ folder.
+ InVendor(pkg string) error
}
// DefaultMissingPackageHandler is the default handler for missing packages.
@@ -70,6 +75,11 @@
return false, nil
}
+func (d *DefaultMissingPackageHandler) InVendor(pkg string) error {
+ msg.Warn("Package %s found in vendor/ folder")
+ return nil
+}
+
// VersionHandler sets the version for a package when found while scanning.
//
// When a package if found it needs to be on the correct version before
@@ -384,6 +394,11 @@
msg.Debug("Marking %s to be scanned.", imp)
r.alreadyQ[imp] = true
queue.PushBack(r.vpath(imp))
+ if err := r.Handler.InVendor(imp); err == nil {
+ r.VersionHandler.SetVersion(imp)
+ } else {
+ msg.Warn("Error updating %s: %s", imp, err)
+ }
r.VersionHandler.SetVersion(imp)
}
case LocUnknown:
@@ -612,7 +627,11 @@
case LocVendor:
//msg.Debug("Vendored: %s", imp)
buf = append(buf, info.Path)
- r.VersionHandler.SetVersion(imp)
+ if err := r.Handler.InVendor(imp); err == nil {
+ r.VersionHandler.SetVersion(imp)
+ } else {
+ msg.Warn("Error updating %s: %s", imp, err)
+ }
case LocGopath:
found, err := r.Handler.OnGopath(imp)
if err != nil {
diff --git a/repo/installer.go b/repo/installer.go
index d85baea..06a3ff1 100644
--- a/repo/installer.go
+++ b/repo/installer.go
@@ -154,12 +154,14 @@
m := &MissingPackageHandler{
destination: vpath,
- cache: i.UseCache,
- cacheGopath: i.UseCacheGopath,
- useGopath: i.UseGopath,
- home: i.Home,
- Config: conf,
- Use: ic,
+ cache: i.UseCache,
+ cacheGopath: i.UseCacheGopath,
+ useGopath: i.UseGopath,
+ home: i.Home,
+ force: i.Force,
+ updateVendored: i.UpdateVendored,
+ Config: conf,
+ Use: ic,
}
v := &VersionHandler{
@@ -245,7 +247,8 @@
for {
select {
case dep := <-ch:
- if err := VcsUpdate(dep, cwd, i); err != nil {
+ dest := filepath.Join(i.VendorPath(), dep.Name)
+ if err := VcsUpdate(dep, dest, i.Home, i.UseCache, i.UseCacheGopath, i.UseGopath, i.Force, i.UpdateVendored); err != nil {
msg.Warn("Update failed for %s: %s\n", dep.Name, err)
// Capture the error while making sure the concurrent
// operations don't step on each other.
@@ -308,12 +311,12 @@
//
// When a package is found on the GOPATH, this notifies the user.
type MissingPackageHandler struct {
- destination string
- home string
- cache, cacheGopath, useGopath bool
- RootPackage string
- Config *cfg.Config
- Use *importCache
+ destination string
+ home string
+ cache, cacheGopath, useGopath, force, updateVendored bool
+ RootPackage string
+ Config *cfg.Config
+ Use *importCache
}
func (m *MissingPackageHandler) NotFound(pkg string) (bool, error) {
@@ -387,6 +390,37 @@
return false, nil
}
+// InVendor updates a package in the vendor/ directory to make sure the latest
+// is available.
+func (m *MissingPackageHandler) InVendor(pkg string) error {
+ root := util.GetRootFromPackage(pkg)
+
+ // Skip any references to the root package.
+ if root == m.RootPackage {
+ return nil
+ }
+
+ dest := filepath.Join(m.destination, root)
+
+ d := m.Config.Imports.Get(root)
+ // If the dependency is nil it means the Config doesn't yet know about it.
+ if d == nil {
+ d = m.Use.Get(root)
+ // We don't know about this dependency so we create a basic instance.
+ if d == nil {
+ d = &cfg.Dependency{Name: root}
+ }
+
+ m.Config.Imports = append(m.Config.Imports, d)
+ }
+
+ if err := VcsUpdate(d, dest, m.home, m.cache, m.cacheGopath, m.useGopath, m.force, m.updateVendored); err != nil {
+ return err
+ }
+
+ return nil
+}
+
// VersionHandler handles setting the proper version in the VCS.
type VersionHandler struct {
diff --git a/repo/vcs.go b/repo/vcs.go
index 091b91c..c54531f 100644
--- a/repo/vcs.go
+++ b/repo/vcs.go
@@ -21,7 +21,7 @@
)
// VcsUpdate updates to a particular checkout based on the VCS setting.
-func VcsUpdate(dep *cfg.Dependency, vend string, inst *Installer) error {
+func VcsUpdate(dep *cfg.Dependency, dest, home string, cache, cacheGopath, useGopath, force, updateVendored bool) error {
// If the dependency has already been pinned we can skip it. This is a
// faster path so we don't need to resolve it again.
@@ -37,10 +37,9 @@
return nil
}
- dest := filepath.Join(vend, dep.Name)
// If destination doesn't exist we need to perform an initial checkout.
if _, err := os.Stat(dest); os.IsNotExist(err) {
- if err = VcsGet(dep, dest, inst.Home, inst.UseCache, inst.UseCacheGopath, inst.UseGopath); err != nil {
+ if err = VcsGet(dep, dest, home, cache, cacheGopath, useGopath); err != nil {
msg.Warn("Unable to checkout %s\n", dep.Name)
return err
}
@@ -54,11 +53,11 @@
return err
}
_, err = v.DetectVcsFromFS(dest)
- if inst.UpdateVendored == false && empty == false && err == v.ErrCannotDetectVCS {
+ if updateVendored == false && empty == false && err == v.ErrCannotDetectVCS {
msg.Warn("%s appears to be a vendored package. Unable to update. Consider the '--update-vendored' flag.\n", dep.Name)
} else {
- if inst.UpdateVendored == true && empty == false && err == v.ErrCannotDetectVCS {
+ if updateVendored == true && empty == false && err == v.ErrCannotDetectVCS {
// A vendored package, no repo, and updating the vendored packages
// has been opted into.
msg.Info("%s is a vendored package. Updating.", dep.Name)
@@ -70,7 +69,7 @@
dep.UpdateAsVendored = true
}
- if err = VcsGet(dep, dest, inst.Home, inst.UseCache, inst.UseCacheGopath, inst.UseGopath); err != nil {
+ if err = VcsGet(dep, dest, home, cache, cacheGopath, useGopath); err != nil {
msg.Warn("Unable to checkout %s\n", dep.Name)
return err
}
@@ -85,7 +84,7 @@
// location can be removed and replaced with the new one.
// Warning, any changes in the old location will be deleted.
// TODO: Put dirty checking in on the existing local checkout.
- if (err == v.ErrWrongVCS || err == v.ErrWrongRemote) && inst.Force == true {
+ if (err == v.ErrWrongVCS || err == v.ErrWrongRemote) && force == true {
var newRemote string
if len(dep.Repository) > 0 {
newRemote = dep.Repository
@@ -98,7 +97,7 @@
if rerr != nil {
return rerr
}
- if err = VcsGet(dep, dest, inst.Home, inst.UseCache, inst.UseCacheGopath, inst.UseGopath); err != nil {
+ if err = VcsGet(dep, dest, home, cache, cacheGopath, useGopath); err != nil {
msg.Warn("Unable to checkout %s\n", dep.Name)
return err
}