Skip to content

fix(diff-parser): handle empty files and mode-only changes in git-style diffs#215

Merged
martintrojer merged 1 commit intoagavra:mainfrom
martintrojer:fix/empty-file-panic
Mar 19, 2026
Merged

fix(diff-parser): handle empty files and mode-only changes in git-style diffs#215
martintrojer merged 1 commit intoagavra:mainfrom
martintrojer:fix/empty-file-panic

Conversation

@martintrojer
Copy link
Copy Markdown
Collaborator

When jj (or git patches) produce diffs for empty new files or mode-only changes, the unified diff output contains no ---/+++ lines. The diff parser relied exclusively on those lines to extract file paths, leaving both old_path and new_path as None. This caused a panic in DiffFile::display_path() which expects at least one path to be present.

Add parse_diff_git_header() to extract paths from the "diff --git a/X b/X" header line as a fallback when parse_file_header() doesn't find ---/+++ or rename/copy metadata.

Reproducer: run tuicr in a jj repo that contains an empty newly-added file (e.g. an empty config.toml).

…le diffs

When jj (or git patches) produce diffs for empty new files or mode-only
changes, the unified diff output contains no ---/+++ lines. The diff
parser relied exclusively on those lines to extract file paths, leaving
both old_path and new_path as None. This caused a panic in
DiffFile::display_path() which expects at least one path to be present.

Add parse_diff_git_header() to extract paths from the
"diff --git a/X b/X" header line as a fallback when parse_file_header()
doesn't find ---/+++ or rename/copy metadata.

Reproducer: run tuicr in a jj repo that contains an empty newly-added
file (e.g. an empty config.toml).
@martintrojer martintrojer force-pushed the fix/empty-file-panic branch from 907b8e5 to c822a7e Compare March 19, 2026 08:27
@martintrojer martintrojer merged commit 3b08d06 into agavra:main Mar 19, 2026
4 checks passed
@martintrojer martintrojer deleted the fix/empty-file-panic branch March 19, 2026 09:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant