4
4
"io/ioutil"
5
5
"os"
6
6
"path/filepath"
7
+ "strings"
7
8
8
9
"github.com/go-git/go-git/v5"
9
10
"github.com/go-git/go-git/v5/plumbing"
@@ -43,7 +44,7 @@ func EnsureDependencies(rootLock models.PackageLock, pkg *models.Package, locked
43
44
}
44
45
deps := pkg .GetParsedDependencies ()
45
46
46
- makeCache (deps )
47
+ // makeCache(deps)
47
48
48
49
ensureModules (rootLock , pkg , deps , lockedVersion )
49
50
@@ -52,13 +53,6 @@ func EnsureDependencies(rootLock models.PackageLock, pkg *models.Package, locked
52
53
return deps
53
54
}
54
55
55
- func makeCache (deps []models.Dependency ) {
56
- msg .Info ("Building cache files..." )
57
- for _ , dep := range deps {
58
- GetDependency (dep )
59
- }
60
- }
61
-
62
56
func processOthers (rootLock models.PackageLock , lockedVersion bool ) []models.Dependency {
63
57
infos , e := ioutil .ReadDir (env .GetModulesDir ())
64
58
var lenProcessedInitial = len (processed )
@@ -106,8 +100,38 @@ func ensureModules(rootLock models.PackageLock, pkg *models.Package, deps []mode
106
100
msg .Info ("Installing modules" )
107
101
for _ , dep := range deps {
108
102
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
+
109
132
repository := gitWrapper .GetRepository (dep )
110
- hasMatch , bestMatch := getVersion (rootLock , dep , repository , lockedVersion )
133
+ hasMatch , bestMatch := getVersion (rootLock , dep , repository , false )
134
+
111
135
var referenceName plumbing.ReferenceName
112
136
113
137
worktree , _ := repository .Worktree ()
0 commit comments