From 2e5a98307e44251f799dc3394731af05c7c6175f Mon Sep 17 00:00:00 2001 From: zeripath Date: Wed, 14 Dec 2022 13:45:33 +0000 Subject: [PATCH] Correctly handle moved files in apply patch (#22118) Backport #22118 Moved files in a patch will result in git apply returning: ``` error: {filename}: No such file or directory ``` This wasn't handled by the git apply patch code. This PR adds handling for this. Fix #22083 Signed-off-by: Andrew Thornton --- services/pull/patch.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/services/pull/patch.go b/services/pull/patch.go index 32895b2e784fc..73ee7ba7eda6f 100644 --- a/services/pull/patch.go +++ b/services/pull/patch.go @@ -52,6 +52,8 @@ var patchErrorSuffices = []string{ ": patch does not apply", ": already exists in working directory", "unrecognized input", + ": No such file or directory", + ": does not exist in index", } // TestPatch will test whether a simple patch will apply @@ -415,6 +417,7 @@ func checkConflicts(ctx context.Context, pr *issues_model.PullRequest, gitRepo * scanner := bufio.NewScanner(stderrReader) for scanner.Scan() { line := scanner.Text() + log.Trace("PullRequest[%d].testPatch: stderr: %s", pr.ID, line) if strings.HasPrefix(line, prefix) { conflict = true filepath := strings.TrimSpace(strings.Split(line[len(prefix):], ":")[0])