Skip to content

Commit

Permalink
Only remove go_replace_directive label, if the rule does not have a m…
Browse files Browse the repository at this point in the history
…atching replace directive
  • Loading branch information
SpangleLabs committed Jul 16, 2024
1 parent d7f7107 commit b166be0
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions sync/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,22 @@ func (s *syncer) syncModFile(conf *config.Config, file *build.File, existingRule
return err
}

// Remove "go_replace_directive" label from all existing rules, before re-adding it only where appropriate
// Remove "go_replace_directive" label from any rules which lack a replace directive
for modPath, rule := range existingRules {
err = edit.RemoveLabel(rule, ReplaceLabel)
if err != nil {
log.Warningf("Failed to remove replace label from %v: %v", modPath, err)
// Find any matching replace directive
var matchingReplace *modfile.Replace
for _, replace := range f.Replace {
if replace.Old.Path == modPath {
matchingReplace = replace
}
}

// Remove the replace label if not needed
if matchingReplace == nil {
err := edit.RemoveLabel(rule, ReplaceLabel)
if err != nil {
log.Warningf("Failed to remove replace label from %v: %v", modPath, err)
}
}
}

Expand Down

0 comments on commit b166be0

Please sign in to comment.