@@ -19,6 +19,7 @@ import (
1919 "strings"
2020
2121 "go.uber.org/zap"
22+ "golang.org/x/mod/modfile"
2223)
2324
2425// Prune prunes the go.mod replace statements.
@@ -55,29 +56,31 @@ func pruneReplace(rootModulePath string, module *moduleInfo, rc RunConfig) {
5556 modContents := & module .moduleContents
5657
5758 // check to see if its intra dependency and no longer present
59+ var toPrune []* modfile.Replace
5860 for _ , rep := range modContents .Replace {
5961 // skip excluded
6062 if _ , exists := rc .ExcludedPaths [rep .Old .Path ]; exists {
61-
6263 rc .Logger .Debug ("Excluded Module, ignoring prune" , zap .String ("excluded_mod" , rep .Old .Path ))
63-
6464 continue
6565 }
6666
6767 if _ , ok := module .requiredReplaceStatements [rep .Old .Path ]; strings .Contains (rep .Old .Path , rootModulePath ) && ! ok {
68- if rc .Verbose {
69- rc .Logger .Debug ("Pruning replace statement" ,
70- zap .String ("module" , modContents .Module .Mod .Path ),
71- zap .String ("replace_statement" , rep .Old .Path + " => " + rep .New .Path ))
72- }
73- err := modContents .DropReplace (rep .Old .Path , rep .Old .Version )
74- if err != nil {
75- rc .Logger .Error ("error dropping replace statement" ,
76- zap .Error (err ),
77- zap .String ("module" , modContents .Module .Mod .Path ),
78- zap .String ("replace_statement" , rep .Old .Path + " => " + rep .New .Path ))
79- }
68+ toPrune = append (toPrune , rep )
69+ }
70+ }
8071
72+ for _ , rep := range toPrune {
73+ if rc .Verbose {
74+ rc .Logger .Debug ("Pruning replace statement" ,
75+ zap .String ("module" , modContents .Module .Mod .Path ),
76+ zap .String ("replace_statement" , rep .Old .Path + " => " + rep .New .Path ))
77+ }
78+ err := modContents .DropReplace (rep .Old .Path , rep .Old .Version )
79+ if err != nil {
80+ rc .Logger .Error ("error dropping replace statement" ,
81+ zap .Error (err ),
82+ zap .String ("module" , modContents .Module .Mod .Path ),
83+ zap .String ("replace_statement" , rep .Old .Path + " => " + rep .New .Path ))
8184 }
8285 }
8386
0 commit comments