From 494a12233ff763de4b5f614588979363b5822009 Mon Sep 17 00:00:00 2001 From: Andrew Thornton Date: Tue, 13 Dec 2022 09:17:52 +0000 Subject: [PATCH 1/3] Correctly handle moved files in apply patch 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 | 1 + 1 file changed, 1 insertion(+) diff --git a/services/pull/patch.go b/services/pull/patch.go index 809b75e6b4536..f3ade6c0e63ac 100644 --- a/services/pull/patch.go +++ b/services/pull/patch.go @@ -53,6 +53,7 @@ var patchErrorSuffices = []string{ ": patch does not apply", ": already exists in working directory", "unrecognized input", + ": No such file or directory", } // TestPatch will test whether a simple patch will apply From 5f2d39c156f30e273696c8dfc37df828f5fd9bae Mon Sep 17 00:00:00 2001 From: Andrew Thornton Date: Tue, 13 Dec 2022 22:33:32 +0000 Subject: [PATCH 2/3] Add trace logging for stderr in check patch Signed-off-by: Andrew Thornton --- services/pull/patch.go | 1 + 1 file changed, 1 insertion(+) diff --git a/services/pull/patch.go b/services/pull/patch.go index f3ade6c0e63ac..0ffd576422da4 100644 --- a/services/pull/patch.go +++ b/services/pull/patch.go @@ -417,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]) From f686bd47266f26c0aea9c2cd8bb92df77a5cf95e Mon Sep 17 00:00:00 2001 From: Andrew Thornton Date: Tue, 13 Dec 2022 22:35:30 +0000 Subject: [PATCH 3/3] And handle "does not exist in index" Signed-off-by: Andrew Thornton --- services/pull/patch.go | 1 + 1 file changed, 1 insertion(+) diff --git a/services/pull/patch.go b/services/pull/patch.go index 0ffd576422da4..e0da410c4d23f 100644 --- a/services/pull/patch.go +++ b/services/pull/patch.go @@ -54,6 +54,7 @@ var patchErrorSuffices = []string{ ": 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