@@ -11,6 +11,7 @@ import (
11
11
"time"
12
12
13
13
"github.com/golang/dep"
14
+ fb "github.com/golang/dep/internal/feedback"
14
15
"github.com/golang/dep/internal/fs"
15
16
"github.com/golang/dep/internal/gps"
16
17
"github.com/golang/dep/internal/gps/paths"
@@ -30,14 +31,19 @@ disable this behavior. The following external tools are supported: glide.
30
31
Any dependencies that are not constrained by external configuration use the
31
32
GOPATH analysis below.
32
33
33
- The version of each dependency will reflect the current state of the GOPATH. If
34
- a dependency doesn't exist in the GOPATH, a version will be selected from the
35
- versions available from the upstream source per the following algorithm:
34
+ By default, the dependencies are resolved over the network. A version will be
35
+ selected from the versions available from the upstream source per the following
36
+ algorithm:
36
37
37
38
- Tags conforming to semver (sorted by semver rules)
38
39
- Default branch(es) (sorted lexicographically)
39
40
- Non-semver tags (sorted lexicographically)
40
41
42
+ An alternate mode can be activated by passing -gopath. In this mode, the version
43
+ of each dependency will reflect the current state of the GOPATH. If a dependency
44
+ doesn't exist in the GOPATH, a version will be selected based on the above
45
+ network version selection algorithm.
46
+
41
47
A Gopkg.toml file will be written with inferred version constraints for all
42
48
direct dependencies. Gopkg.lock will be written with precise versions, and
43
49
vendor/ will be populated with the precise versions written to Gopkg.lock.
@@ -52,11 +58,13 @@ func (cmd *initCommand) Hidden() bool { return false }
52
58
func (cmd * initCommand ) Register (fs * flag.FlagSet ) {
53
59
fs .BoolVar (& cmd .noExamples , "no-examples" , false , "don't include example in Gopkg.toml" )
54
60
fs .BoolVar (& cmd .skipTools , "skip-tools" , false , "skip importing configuration from other dependency managers" )
61
+ fs .BoolVar (& cmd .gopath , "gopath" , false , "search in GOPATH for dependencies" )
55
62
}
56
63
57
64
type initCommand struct {
58
65
noExamples bool
59
66
skipTools bool
67
+ gopath bool
60
68
}
61
69
62
70
func (cmd * initCommand ) Run (ctx * dep.Ctx , args []string ) error {
@@ -119,10 +127,13 @@ func (cmd *initCommand) Run(ctx *dep.Ctx, args []string) error {
119
127
if err != nil {
120
128
return err
121
129
}
130
+
122
131
gs := newGopathScanner (ctx , directDeps , sm )
123
- err = gs .InitializeRootManifestAndLock (m , l )
124
- if err != nil {
125
- return err
132
+ if cmd .gopath {
133
+ err = gs .InitializeRootManifestAndLock (m , l )
134
+ if err != nil {
135
+ return err
136
+ }
126
137
}
127
138
128
139
rootAnalyzer .skipTools = true // Don't import external config during solve for now
@@ -152,7 +163,20 @@ func (cmd *initCommand) Run(ctx *dep.Ctx, args []string) error {
152
163
l = dep .LockFromSolution (soln )
153
164
154
165
rootAnalyzer .FinalizeRootManifestAndLock (m , l )
155
- gs .FinalizeRootManifestAndLock (m , l )
166
+ if cmd .gopath {
167
+ gs .FinalizeRootManifestAndLock (m , l )
168
+ } else {
169
+ // Pick the direct dependencies from the above solution and add to manifest
170
+ for _ , x := range l .Projects () {
171
+ pr := x .Ident ().ProjectRoot
172
+ if _ , ok := directDeps [string (pr )]; ok {
173
+ m .Constraints [pr ] = getProjectPropertiesFromVersion (x .Version ())
174
+ feedback (x .Version (), pr , fb .DepTypeDirect , ctx .Err )
175
+ } else {
176
+ feedback (x .Version (), pr , fb .DepTypeTransitive , ctx .Err )
177
+ }
178
+ }
179
+ }
156
180
157
181
// Run gps.Prepare with appropriate constraint solutions from solve run
158
182
// to generate the final lock memo.
0 commit comments