From 05a699c32e38fdcd1696a316dac5fa49ce927e02 Mon Sep 17 00:00:00 2001 From: Ayooluwa Isaiah Date: Thu, 31 Oct 2024 23:42:08 +0100 Subject: [PATCH] detect conflicts correctly --- validate/validate.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/validate/validate.go b/validate/validate.go index 558963e..1962998 100644 --- a/validate/validate.go +++ b/validate/validate.go @@ -444,28 +444,33 @@ func checkAndHandleConflict(ctx validationCtx, loopIndex *int) (detected bool) { // detectConflicts checks the renamed files for various conflicts and // automatically fixes them if configured. -func detectConflicts(autoFix, allowOverwrites bool) (detected bool) { +func detectConflicts(autoFix, allowOverwrites bool) bool { ctx := validationCtx{ autoFix: autoFix, allowOverwrites: allowOverwrites, seenPaths: make(map[string]int), } + conflicts := make(map[int]string) + for i := 0; i < len(changes); i++ { change := changes[i] ctx.change = change ctx.changeIndex = i - detected = checkAndHandleConflict(ctx, &i) + detected := checkAndHandleConflict(ctx, &i) if detected { + conflicts[ctx.changeIndex] = change.SourcePath continue } + delete(conflicts, ctx.changeIndex) + ctx.updateSeenPaths() } - return + return len(conflicts) > 0 } // Validate detects and reports any conflicts that can occur while renaming a