Skip to content
This repository was archived by the owner on Sep 9, 2020. It is now read-only.

Commit 9e1b219

Browse files
committed
Populate the list of dependencies to update from the command arguments
Instead of munging the lock to allow some projects to be updated, make use of the ToChange parameter.
1 parent db9e1d0 commit 9e1b219

File tree

1 file changed

+28
-37
lines changed

1 file changed

+28
-37
lines changed

cmd/dep/ensure.go

Lines changed: 28 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -118,41 +118,42 @@ func (cmd *ensureCommand) Run(ctx *dep.Ctx, args []string) error {
118118
sm.UseDefaultSignalHandling()
119119
defer sm.Release()
120120

121+
params := p.MakeParams()
122+
if cmd.update && len(args) == 0 {
123+
// If -update was specified without args, we want the solver to allow all versions to change
124+
params.ChangeAll = cmd.update
125+
}
126+
121127
var errs []error
122128
for _, arg := range args {
123-
// default persist to manifest
124129
pc, err := getProjectConstraint(arg, sm)
125130
if err != nil {
126131
errs = append(errs, err)
127132
continue
128133
}
129134

130-
if gps.IsAny(pc.Constraint) && pc.Ident.Source == "" {
131-
// If the input specified neither a network name nor a constraint,
132-
// then the strict thing to do would be to remove the entry
133-
// entirely. But that would probably be quite surprising for users,
134-
// and it's what rm is for, so just ignore the input.
135-
//
136-
// TODO(sdboyer): for this case - or just in general - do we want to
137-
// add project args to the requires list temporarily for this run?
138-
if _, has := p.Manifest.Dependencies[pc.Ident.ProjectRoot]; !has {
139-
logf("No constraint or alternate source specified for %q, omitting from manifest", pc.Ident.ProjectRoot)
135+
// Ignore the lockfile for this dependency and allow its version to change
136+
params.ToChange = append(params.ToChange, pc.Ident.ProjectRoot)
137+
138+
if !cmd.update {
139+
if gps.IsAny(pc.Constraint) && pc.Ident.Source == "" {
140+
// If the input specified neither a network name nor a constraint,
141+
// then the strict thing to do would be to remove the entry
142+
// entirely. But that would probably be quite surprising for users,
143+
// and it's what rm is for, so just ignore the input.
144+
//
145+
// TODO(sdboyer): for this case - or just in general - do we want to
146+
// add project args to the requires list temporarily for this run?
147+
if _, has := p.Manifest.Dependencies[pc.Ident.ProjectRoot]; !has {
148+
logf("No constraint or alternate source specified for %q, omitting from manifest", pc.Ident.ProjectRoot)
149+
}
150+
// If it's already in the manifest, no need to log
151+
continue
140152
}
141-
// If it's already in the manifest, no need to log
142-
continue
143-
}
144-
145-
p.Manifest.Dependencies[pc.Ident.ProjectRoot] = gps.ProjectProperties{
146-
Source: pc.Ident.Source,
147-
Constraint: pc.Constraint,
148-
}
149153

150-
if p.Lock != nil {
151-
for i, lp := range p.Lock.P {
152-
if lp.Ident() == pc.Ident {
153-
p.Lock.P = append(p.Lock.P[:i], p.Lock.P[i+1:]...)
154-
break
155-
}
154+
p.Manifest.Dependencies[pc.Ident.ProjectRoot] = gps.ProjectProperties{
155+
Source: pc.Ident.Source,
156+
Constraint: pc.Constraint,
156157
}
157158
}
158159
}
@@ -173,14 +174,8 @@ func (cmd *ensureCommand) Run(ctx *dep.Ctx, args []string) error {
173174
Constraint: pc.Constraint,
174175
}
175176

176-
if p.Lock != nil {
177-
for i, lp := range p.Lock.P {
178-
if lp.Ident() == pc.Ident {
179-
p.Lock.P = append(p.Lock.P[:i], p.Lock.P[i+1:]...)
180-
break
181-
}
182-
}
183-
}
177+
// Ignore the lockfile for this dependency and allow its version to change
178+
params.ToChange = append(params.ToChange, pc.Ident.ProjectRoot)
184179
}
185180

186181
if len(errs) > 0 {
@@ -192,10 +187,6 @@ func (cmd *ensureCommand) Run(ctx *dep.Ctx, args []string) error {
192187
return errors.New(buf.String())
193188
}
194189

195-
params := p.MakeParams()
196-
// If -update was passed, we want the solver to allow all versions to change
197-
params.ChangeAll = cmd.update
198-
199190
if *verbose {
200191
params.Trace = true
201192
params.TraceLogger = log.New(os.Stderr, "", 0)

0 commit comments

Comments
 (0)