Backport #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 #18514 Signed-off-by: Andrew Thornton <art27@cantab.net>
This commit is contained in:
parent
1d17313949
commit
0dfe5fa2d6
1 changed files with 13 additions and 0 deletions
|
@ -339,8 +339,10 @@ func checkConflicts(pr *models.PullRequest, gitRepo *git.Repository, tmpBasePath
|
||||||
if prConfig.IgnoreWhitespaceConflicts {
|
if prConfig.IgnoreWhitespaceConflicts {
|
||||||
args = append(args, "--ignore-whitespace")
|
args = append(args, "--ignore-whitespace")
|
||||||
}
|
}
|
||||||
|
is3way := false
|
||||||
if git.CheckGitVersionAtLeast("2.32.0") == nil {
|
if git.CheckGitVersionAtLeast("2.32.0") == nil {
|
||||||
args = append(args, "--3way")
|
args = append(args, "--3way")
|
||||||
|
is3way = true
|
||||||
}
|
}
|
||||||
args = append(args, patchPath)
|
args = append(args, patchPath)
|
||||||
pr.ConflictedFiles = make([]string, 0, 5)
|
pr.ConflictedFiles = make([]string, 0, 5)
|
||||||
|
@ -379,6 +381,9 @@ func checkConflicts(pr *models.PullRequest, gitRepo *git.Repository, tmpBasePath
|
||||||
|
|
||||||
const prefix = "error: patch failed:"
|
const prefix = "error: patch failed:"
|
||||||
const errorPrefix = "error: "
|
const errorPrefix = "error: "
|
||||||
|
const threewayFailed = "Failed to perform three-way merge..."
|
||||||
|
const appliedPatchPrefix = "Applied patch to '"
|
||||||
|
const withConflicts = "' with conflicts."
|
||||||
|
|
||||||
conflictMap := map[string]bool{}
|
conflictMap := map[string]bool{}
|
||||||
|
|
||||||
|
@ -390,6 +395,8 @@ func checkConflicts(pr *models.PullRequest, gitRepo *git.Repository, tmpBasePath
|
||||||
conflict = true
|
conflict = true
|
||||||
filepath := strings.TrimSpace(strings.Split(line[len(prefix):], ":")[0])
|
filepath := strings.TrimSpace(strings.Split(line[len(prefix):], ":")[0])
|
||||||
conflictMap[filepath] = true
|
conflictMap[filepath] = true
|
||||||
|
} else if is3way && line == threewayFailed {
|
||||||
|
conflict = true
|
||||||
} else if strings.HasPrefix(line, errorPrefix) {
|
} else if strings.HasPrefix(line, errorPrefix) {
|
||||||
conflict = true
|
conflict = true
|
||||||
for _, suffix := range patchErrorSuffices {
|
for _, suffix := range patchErrorSuffices {
|
||||||
|
@ -401,6 +408,12 @@ func checkConflicts(pr *models.PullRequest, gitRepo *git.Repository, tmpBasePath
|
||||||
break
|
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
|
// only list 10 conflicted files
|
||||||
if len(conflictMap) >= 10 {
|
if len(conflictMap) >= 10 {
|
||||||
|
|
Reference in a new issue