From 842fedadf44cd4f4e9ca428397de5166cf89d024 Mon Sep 17 00:00:00 2001 From: Andrew Thornton Date: Tue, 1 Feb 2022 21:16:37 +0000 Subject: [PATCH 1/2] Detect conflicts with 3way merge 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 #18514 Signed-off-by: Andrew Thornton --- services/pull/patch.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/services/pull/patch.go b/services/pull/patch.go index a6321679163e7..5d4d7d1cb93b1 100644 --- a/services/pull/patch.go +++ b/services/pull/patch.go @@ -343,8 +343,10 @@ func checkConflicts(pr *models.PullRequest, gitRepo *git.Repository, tmpBasePath if prConfig.IgnoreWhitespaceConflicts { args = append(args, "--ignore-whitespace") } + is3way := false if git.CheckGitVersionAtLeast("2.32.0") == nil { args = append(args, "--3way") + is3way = true } args = append(args, patchPath) pr.ConflictedFiles = make([]string, 0, 5) @@ -383,6 +385,9 @@ func checkConflicts(pr *models.PullRequest, gitRepo *git.Repository, tmpBasePath const prefix = "error: patch failed:" const errorPrefix = "error: " + const threewayFailed = "Failed to perform three-way merge..." + const appliedPatchPrefix = "Applied patch to '" + const withConflicts = "' with conflicts." conflictMap := map[string]bool{} @@ -405,6 +410,12 @@ func checkConflicts(pr *models.PullRequest, gitRepo *git.Repository, tmpBasePath break } } + } else if is3way && strings.HasPrefix(line, appliedPatchPrefix) && strings.HasSuffix(line, withConflicts) { + conflict = true + filepath := strings.TrimPrefix(strings.TrimSuffix(line, withConflicts), appliedPatchPrefix) + if filepath != "" { + conflictMap[filepath] = true + } } // only list 10 conflicted files if len(conflictMap) >= 10 { From 3cc2fa6a9e5bd40549257da4b15458821a6141b1 Mon Sep 17 00:00:00 2001 From: Andrew Thornton Date: Tue, 1 Feb 2022 21:20:05 +0000 Subject: [PATCH 2/2] and three-way failed Signed-off-by: Andrew Thornton --- services/pull/patch.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/services/pull/patch.go b/services/pull/patch.go index 5d4d7d1cb93b1..c10d7dfbfbaea 100644 --- a/services/pull/patch.go +++ b/services/pull/patch.go @@ -399,6 +399,8 @@ func checkConflicts(pr *models.PullRequest, gitRepo *git.Repository, tmpBasePath conflict = true filepath := strings.TrimSpace(strings.Split(line[len(prefix):], ":")[0]) conflictMap[filepath] = true + } else if is3way && line == threewayFailed { + conflict = true } else if strings.HasPrefix(line, errorPrefix) { conflict = true for _, suffix := range patchErrorSuffices {