From 347fb46451f002c3557ec4cdd96ed69556d1895c Mon Sep 17 00:00:00 2001 From: Jonathan Schneider Date: Tue, 27 Jan 2026 08:57:10 -0500 Subject: [PATCH] Include file path in patch apply exception messages When a patch fails to apply, the error message now includes the file path being patched, making it easier to debug which file caused the failure. Previously, only the HunkHeader information (line start/count) was shown, which could be ambiguous when the same pattern exists in multiple files. Fixes moderneinc/customer-requests#1759 --- .../main/java/org/openrewrite/jgit/api/ApplyCommand.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/jgit/src/main/java/org/openrewrite/jgit/api/ApplyCommand.java b/jgit/src/main/java/org/openrewrite/jgit/api/ApplyCommand.java index ff06275e7..e127d0ca2 100644 --- a/jgit/src/main/java/org/openrewrite/jgit/api/ApplyCommand.java +++ b/jgit/src/main/java/org/openrewrite/jgit/api/ApplyCommand.java @@ -600,7 +600,7 @@ private void applyText(Repository repository, String path, RawText rt, // We assume hunks to be ordered if (hh.getNewStartLine() <= lastHunkNewLine) { throw new PatchApplyException(MessageFormat - .format(JGitText.get().patchApplyException, hh)); + .format(JGitText.get().patchApplyErrorWithHunk, path, hh, "hunk out of sequence")); } lastHunkNewLine = hh.getNewStartLine(); @@ -622,7 +622,7 @@ && canApplyAt(hunkLines, newLines, 0)) { break; } throw new PatchApplyException(MessageFormat - .format(JGitText.get().patchApplyException, hh)); + .format(JGitText.get().patchApplyErrorWithHunk, path, hh, "cannot apply hunk")); } // Hunk lines as reported by the hunk may be off, so don't rely on // them. @@ -634,7 +634,7 @@ && canApplyAt(hunkLines, newLines, 0)) { } if (applyAt < afterLastHunk) { throw new PatchApplyException(MessageFormat - .format(JGitText.get().patchApplyException, hh)); + .format(JGitText.get().patchApplyErrorWithHunk, path, hh, "hunk application position overlaps with previous hunk")); } boolean applies = false; int oldLinesInHunk = hh.getLinesContext() @@ -673,7 +673,7 @@ && canApplyAt(hunkLines, newLines, 0)) { } if (!applies) { throw new PatchApplyException(MessageFormat - .format(JGitText.get().patchApplyException, hh)); + .format(JGitText.get().patchApplyErrorWithHunk, path, hh, "hunk does not apply to file content")); } // Hunk applies at applyAt. Apply it, and update afterLastHunk and // lineNumberShift