@@ -241,7 +241,7 @@ func (cmd *ensureCommand) runDefault(ctx *dep.Ctx, args []string, p *dep.Project
241
241
242
242
solver , err := gps .Prepare (params , sm )
243
243
if err != nil {
244
- return errors .Wrap (err , "ensure Prepare " )
244
+ return errors .Wrap (err , "prepare solver " )
245
245
}
246
246
247
247
if p .Lock != nil && bytes .Equal (p .Lock .InputHash (), solver .HashInputs ()) {
@@ -290,13 +290,32 @@ func (cmd *ensureCommand) runUpdate(ctx *dep.Ctx, args []string, p *dep.Project,
290
290
return errors .New ("%s does not exist. nothing to do, as -update works by updating the values in %s." , dep .LockName , dep .LockName )
291
291
}
292
292
293
- // When -update is specified without args, allow every project to change versions, regardless of the lock file
293
+ // We'll need to discard this prepared solver as later work changes params,
294
+ // but solver preparation is cheap and worth doing up front in order to
295
+ // perform the fastpath check of hash comparison.
296
+ solver , err := gps .Prepare (params , sm )
297
+ if err != nil {
298
+ return errors .Wrap (err , "fastpath solver prepare" )
299
+ }
300
+
301
+ // Compare the hashes. If they're not equal, bail out and ask the user to
302
+ // run a straight `dep ensure` before updating. This is handholding the
303
+ // user a bit, but the extra effort required is minimal, and it ensures the
304
+ // user is isolating variables in the event of solve problems (was it the
305
+ // existing changes, or the -update that caused the problem?).
306
+ if bytes .Equal (p .Lock .InputHash (), solver .HashInputs ()) {
307
+ return errors .Errorf ("%s and %s are out of sync. run a plain `dep ensure` to resync them before attempting an -update." , dep .ManifestName , dep .LockName )
308
+ }
309
+
310
+ // When -update is specified without args, allow every dependency to change
311
+ // versions, regardless of the lock file.
294
312
if len (args ) == 0 {
295
313
params .ChangeAll = true
296
314
return
297
315
}
298
316
299
- // Allow any of specified project versions to change, regardless of the lock file
317
+ // Allow any of specified project versions to change, regardless of the lock
318
+ // file.
300
319
for _ , arg := range args {
301
320
// Ensure the provided path has a deducible project root
302
321
// TODO(sdboyer) do these concurrently
@@ -308,6 +327,10 @@ func (cmd *ensureCommand) runUpdate(ctx *dep.Ctx, args []string, p *dep.Project,
308
327
return err
309
328
}
310
329
330
+ if ! p .Lock .HasProjectWithRoot (pc .Ident .ProjectRoot ) {
331
+ return errors .Errorf ("%s is not present in %s, cannot -update it" , pc .Ident .ProjectRoot , dep .LockName )
332
+ }
333
+
311
334
if ! gps .IsAny (pc .Constraint ) {
312
335
// TODO(sdboyer) constraints should be allowed to allow solves that
313
336
// target particular versions while remaining within declared constraints
@@ -316,6 +339,28 @@ func (cmd *ensureCommand) runUpdate(ctx *dep.Ctx, args []string, p *dep.Project,
316
339
317
340
params .ToChange = append (params .ToChange , gps .ProjectRoot (arg ))
318
341
}
342
+
343
+ // Re-prepare a solver now that our params are complete.
344
+ solver , err = gps .Prepare (params , sm )
345
+ if err != nil {
346
+ return errors .Wrap (err , "fastpath solver prepare" )
347
+ }
348
+ solution , err := solver .Solve ()
349
+ if err != nil {
350
+ handleAllTheFailuresOfTheWorld (err )
351
+ return errors .Wrap (err , "ensure Solve()" )
352
+ }
353
+
354
+ var sw dep.SafeWriter
355
+ sw .Prepare (nil , p .Lock , dep .LockFromInterface (solution ), dep .VendorOnChanged )
356
+ // TODO(sdboyer) special handling for warning cases as described in spec -
357
+ // e.g., named projects did not upgrade even though newer versions were
358
+ // available.
359
+ if cmd .dryRun {
360
+ return sw .PrintPreparedActions ()
361
+ }
362
+
363
+ return errors .Wrap (sw .Write (p .AbsRoot , sm , true ), "grouped write of manifest, lock and vendor" )
319
364
}
320
365
321
366
func (cmd * ensureCommand ) runAdd (ctx * dep.Ctx , args []string , p * dep.Project , sm gps.SourceManager , params gps.SolveParameters ) error {
@@ -395,6 +440,8 @@ func (s *stringSlice) Set(value string) error {
395
440
}
396
441
397
442
func getProjectConstraint (arg string , sm * gps.SourceMgr ) (gps.ProjectConstraint , error ) {
443
+ // TODO(sdboyer) this func needs to be broken out, now that we admit
444
+ // different info in specs
398
445
constraint := gps.ProjectConstraint {
399
446
Constraint : gps .Any (), // default to any; avoids panics later
400
447
}
0 commit comments