Preserve replacement selectors during recovery

This commit is contained in:
2026-11-04 01:25:34 +00:00
parent ec67496569
commit b5c6638538
4 changed files with 57 additions and 14 deletions

View File

@@ -100,9 +100,11 @@ func RecoveryTool(ctx context.Context, moduleDir, recordDir string) (*RecoveryIn
// replacements relative to the directory that originally owned go.mod.
for _, replacement := range module.Replace {
if replacement.New.Version == "" && !filepath.IsAbs(replacement.New.Path) {
if err := module.AddReplace(replacement.Old.Path, replacement.Old.Version, filepath.Join(moduleDir, replacement.New.Path), ""); err != nil {
return nil, err
}
// A local replacement ends in its path token. Edit that token on
// the parsed directive so a wildcard does not absorb versioned ones.
replacement.New.Path = filepath.Join(moduleDir, replacement.New.Path)
tokens := replacement.Syntax.Token
tokens[len(tokens)-1] = modfile.AutoQuote(replacement.New.Path)
}
}
// The original main module's source remains local if a dependency refers