diff options
author | zeripath <art27@cantab.net> | 2022-02-02 04:46:10 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-02 12:46:10 +0800 |
commit | 92e81e97e848f95af437694297105ec8fa18365e (patch) | |
tree | ae1a5fefba29e147fef07b207787e2d1a537617f | |
parent | 5469e61a8e750daad05ddc8b9b2110b1cda4bb68 (diff) | |
download | gitea-92e81e97e848f95af437694297105ec8fa18365e.tar.gz gitea-92e81e97e848f95af437694297105ec8fa18365e.zip |
Detect conflicts with 3way merge (#18536)
* 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 <art27@cantab.net>
* and three-way failed
Signed-off-by: Andrew Thornton <art27@cantab.net>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
-rw-r--r-- | services/pull/patch.go | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/services/pull/patch.go b/services/pull/patch.go index a632167916..c10d7dfbfb 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{} @@ -394,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 { @@ -405,6 +412,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 { |