Skip to content

Commit d85bb24

Browse files
committed
Detect conflicts with 3way merge (go-gitea#18536)
Backport go-gitea#18536 Unforunately git apply --3way reports conflicts differently than standard patches resulting in conflicts being missed. Adjust the conflict detection code to account for this different error reporting. Fix go-gitea#18514 Signed-off-by: Andrew Thornton <[email protected]>
1 parent f7606de commit d85bb24

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

services/pull/patch.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,8 +339,10 @@ func checkConflicts(pr *models.PullRequest, gitRepo *git.Repository, tmpBasePath
339339
if prConfig.IgnoreWhitespaceConflicts {
340340
args = append(args, "--ignore-whitespace")
341341
}
342+
is3way := false
342343
if git.CheckGitVersionAtLeast("2.32.0") == nil {
343344
args = append(args, "--3way")
345+
is3way = true
344346
}
345347
args = append(args, patchPath)
346348
pr.ConflictedFiles = make([]string, 0, 5)
@@ -379,6 +381,9 @@ func checkConflicts(pr *models.PullRequest, gitRepo *git.Repository, tmpBasePath
379381

380382
const prefix = "error: patch failed:"
381383
const errorPrefix = "error: "
384+
const threewayFailed = "Failed to perform three-way merge..."
385+
const appliedPatchPrefix = "Applied patch to '"
386+
const withConflicts = "' with conflicts."
382387

383388
conflictMap := map[string]bool{}
384389

@@ -401,6 +406,12 @@ func checkConflicts(pr *models.PullRequest, gitRepo *git.Repository, tmpBasePath
401406
break
402407
}
403408
}
409+
} else if is3way && strings.HasPrefix(line, appliedPatchPrefix) && strings.HasSuffix(line, withConflicts) {
410+
conflict = true
411+
filepath := strings.TrimPrefix(strings.TrimSuffix(line, withConflicts), appliedPatchPrefix)
412+
if filepath != "" {
413+
conflictMap[filepath] = true
414+
}
404415
}
405416
// only list 10 conflicted files
406417
if len(conflictMap) >= 10 {

0 commit comments

Comments
 (0)