Skip to content

Commit ea0b9e3

Browse files
Strip git format-patch footer before parsing (#34)
* Initial plan * Strip git format-patch footer before parsing patch content Co-authored-by: unknowIfGuestInDream <57802425+unknowIfGuestInDream@users.noreply.github.com> * Fix regex escaping for git format-patch footer stripping Co-authored-by: unknowIfGuestInDream <57802425+unknowIfGuestInDream@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: unknowIfGuestInDream <57802425+unknowIfGuestInDream@users.noreply.github.com>
1 parent 855638b commit ea0b9e3

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/patchEditorProvider.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -869,6 +869,17 @@ export class PatchEditorProvider implements vscode.CustomTextEditorProvider {
869869
});
870870
}
871871
872+
// Strip git format-patch footer (e.g., "-- \n2.43.0\n")
873+
// This footer is added by git format-patch and should not be parsed as diff content
874+
function stripGitPatchFooter(content) {
875+
if (!content) return content;
876+
// Match the git email signature footer: "-- " followed by newline and version info
877+
// The footer starts with "-- " on its own line (with possible trailing whitespace)
878+
// followed by a git version number (e.g., "2.43.0") on the next line
879+
var footerPattern = new RegExp('\\n-- \\n[0-9]+\\.[0-9]+[^\\n]*\\n?$');
880+
return content.replace(footerPattern, '\n');
881+
}
882+
872883
// Render diff using diff2html
873884
function renderDiff() {
874885
if (!currentContent || !currentContent.trim()) {
@@ -892,8 +903,11 @@ export class PatchEditorProvider implements vscode.CustomTextEditorProvider {
892903
try {
893904
const outputFormat = currentViewMode === 'side-by-side' ? 'side-by-side' : 'line-by-line';
894905
906+
// Strip git format-patch footer before parsing
907+
const contentToParse = stripGitPatchFooter(currentContent);
908+
895909
// First, try to parse the diff content
896-
const diffJson = Diff2HtmlLib.parse(currentContent, {
910+
const diffJson = Diff2HtmlLib.parse(contentToParse, {
897911
inputFormat: 'diff'
898912
});
899913

0 commit comments

Comments
 (0)