Skip to content

Commit 80f6fb9

Browse files
author
andriws.luna
committed
install fetch repo only when necessary
1 parent 3f06db9 commit 80f6fb9

File tree

1 file changed

+33
-9
lines changed

1 file changed

+33
-9
lines changed

core/installer/core.go

+33-9
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"io/ioutil"
55
"os"
66
"path/filepath"
7+
"strings"
78

89
"github.com/go-git/go-git/v5"
910
"github.com/go-git/go-git/v5/plumbing"
@@ -43,7 +44,7 @@ func EnsureDependencies(rootLock models.PackageLock, pkg *models.Package, locked
4344
}
4445
deps := pkg.GetParsedDependencies()
4546

46-
makeCache(deps)
47+
//makeCache(deps)
4748

4849
ensureModules(rootLock, pkg, deps, lockedVersion)
4950

@@ -52,13 +53,6 @@ func EnsureDependencies(rootLock models.PackageLock, pkg *models.Package, locked
5253
return deps
5354
}
5455

55-
func makeCache(deps []models.Dependency) {
56-
msg.Info("Building cache files...")
57-
for _, dep := range deps {
58-
GetDependency(dep)
59-
}
60-
}
61-
6256
func processOthers(rootLock models.PackageLock, lockedVersion bool) []models.Dependency {
6357
infos, e := ioutil.ReadDir(env.GetModulesDir())
6458
var lenProcessedInitial = len(processed)
@@ -106,8 +100,38 @@ func ensureModules(rootLock models.PackageLock, pkg *models.Package, deps []mode
106100
msg.Info("Installing modules")
107101
for _, dep := range deps {
108102
msg.Info("Processing dependency %s", dep.GetName())
103+
104+
installed, exists := rootLock.Installed[strings.ToLower(dep.GetURL())]
105+
106+
if lockedVersion && exists {
107+
depv := strings.Replace(strings.Replace(dep.GetVersion(), "^", "", -1), "~", "", -1)
108+
requiredVersion, err := semver.NewVersion(depv)
109+
110+
if err != nil {
111+
msg.Warn(" Error '%s' on get required version. Updating...", err)
112+
113+
} else {
114+
installedVersion, err := semver.NewVersion(installed.Version)
115+
116+
if err != nil {
117+
msg.Warn(" Error '%s' on get installed version. Updating...", err)
118+
} else {
119+
if !installedVersion.LessThan(requiredVersion) {
120+
msg.Info("Dependency %s already installed", dep.GetName())
121+
continue
122+
} else {
123+
msg.Info("Dependency %s needs to update", dep.GetName())
124+
}
125+
}
126+
}
127+
128+
}
129+
//git fetch only when necessary
130+
GetDependency(dep)
131+
109132
repository := gitWrapper.GetRepository(dep)
110-
hasMatch, bestMatch := getVersion(rootLock, dep, repository, lockedVersion)
133+
hasMatch, bestMatch := getVersion(rootLock, dep, repository, false)
134+
111135
var referenceName plumbing.ReferenceName
112136

113137
worktree, _ := repository.Worktree()

0 commit comments

Comments
 (0)