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