@@ -432,6 +432,7 @@ const (
432
432
missingFromTree
433
433
projectAdded
434
434
projectRemoved
435
+ pathPreserved
435
436
)
436
437
437
438
// NewDeltaWriter prepares a vendor writer that will construct a vendor
@@ -510,17 +511,26 @@ func NewDeltaWriter(p *Project, newLock *Lock, behavior VendorBehavior) (TreeWri
510
511
// We don't validate this field elsewhere as it can be difficult to know
511
512
// at the beginning of a dep ensure command whether or not the noverify
512
513
// project actually will exist as part of the Lock by the end of the
513
- // run. So, only apply if it's in the lockdiff, and isn't a removal .
514
+ // run. So, only apply if it's in the lockdiff.
514
515
if _ , has := dw .lockDiff .ProjectDeltas [pr ]; has {
515
- if typ , has := dw .changed [pr ]; has && typ < noVerify {
516
- // Avoid writing noverify projects at all for the lower change
517
- // types.
518
- delete (dw .changed , pr )
519
-
520
- // Uncomment this if we want to switch to the safer behavior,
521
- // where we ALWAYS write noverify projects.
522
- //dw.changed[pr] = noVerify
516
+ if typ , has := dw .changed [pr ]; has {
517
+ if typ < noVerify {
518
+ // Avoid writing noverify projects at all for the lower change
519
+ // types.
520
+ delete (dw .changed , pr )
521
+
522
+ // Uncomment this if we want to switch to the safer behavior,
523
+ // where we ALWAYS write noverify projects.
524
+ //dw.changed[pr] = noVerify
525
+ } else if typ == projectRemoved {
526
+ // noverify can also be used to preserve files that would
527
+ // otherwise be removed.
528
+ dw .changed [pr ] = pathPreserved
529
+ }
523
530
}
531
+ // It's also allowed to preserve entirely unknown paths using noverify.
532
+ } else if _ , has := status [spr ]; has {
533
+ dw .changed [pr ] = pathPreserved
524
534
}
525
535
}
526
536
@@ -564,29 +574,28 @@ func (dw *DeltaWriter) Write(path string, sm gps.SourceManager, examples bool, l
564
574
projs [lp .Ident ().ProjectRoot ] = lp
565
575
}
566
576
567
- dropped := []gps.ProjectRoot {}
577
+ var dropped , preserved []gps.ProjectRoot
568
578
i := 0
569
579
tot := len (dw .changed )
570
- if len (dw .changed ) > 0 {
571
- logger .Println ("# Bringing vendor into sync" )
580
+ for _ , reason := range dw .changed {
581
+ if reason != pathPreserved {
582
+ logger .Println ("# Bringing vendor into sync" )
583
+ break
584
+ }
572
585
}
586
+
573
587
for pr , reason := range dw .changed {
574
- if reason == projectRemoved {
588
+ switch reason {
589
+ case projectRemoved :
575
590
dropped = append (dropped , pr )
576
591
continue
592
+ case pathPreserved :
593
+ preserved = append (preserved , pr )
594
+ continue
577
595
}
578
596
579
597
to := filepath .FromSlash (filepath .Join (vnewpath , string (pr )))
580
- proj , has := projs [pr ]
581
- if ! has {
582
- // This shouldn't be reachable, but it's preferable to print an
583
- // error and continue rather than panic. https://github.com/golang/dep/issues/1945
584
- // TODO(sdboyer) remove this once we've increased confidence around
585
- // this case.
586
- fmt .Fprintf (os .Stderr , "Internal error - %s had change code %v but was not in new Gopkg.lock. Re-running dep ensure should fix this. Please file a bug at https://github.com/golang/dep/issues/new!\n " , pr , reason )
587
- continue
588
- }
589
- po := proj .(verify.VerifiableProject ).PruneOpts
598
+ po := projs [pr ].(verify.VerifiableProject ).PruneOpts
590
599
if err := sm .ExportPrunedProject (context .TODO (), projs [pr ], po , to ); err != nil {
591
600
return errors .Wrapf (err , "failed to export %s" , pr )
592
601
}
@@ -666,13 +675,18 @@ func (dw *DeltaWriter) Write(path string, sm gps.SourceManager, examples bool, l
666
675
}
667
676
}
668
677
669
- // Ensure vendor/.git is preserved if present
678
+ // Special case: ensure vendor/.git is preserved if present
670
679
if hasDotGit (vpath ) {
671
- err = fs .RenameWithFallback (filepath .Join (vpath , ".git" ), filepath .Join (vnewpath , ".git" ))
680
+ preserved = append (preserved , ".git" )
681
+ }
682
+
683
+ for _ , path := range preserved {
684
+ err = fs .RenameWithFallback (filepath .Join (vpath , string (path )), filepath .Join (vnewpath , string (path )))
672
685
if err != nil {
673
- return errors .Wrap (err , "failed to preserve vendor/.git" )
686
+ return errors .Wrapf (err , "failed to preserve vendor/%s" , path )
674
687
}
675
688
}
689
+
676
690
err = os .RemoveAll (vpath )
677
691
if err != nil {
678
692
return errors .Wrap (err , "failed to remove original vendor directory" )
0 commit comments