fix: handle file mode changes (old mode/new mode) in diff parsing#41
Merged
yeonjuan merged 3 commits intoyeonjuan:mainfrom Feb 14, 2026
Merged
fix: handle file mode changes (old mode/new mode) in diff parsing#41yeonjuan merged 3 commits intoyeonjuan:mainfrom
yeonjuan merged 3 commits intoyeonjuan:mainfrom
Conversation
Files with `old mode`/`new mode` extended headers were not parsed correctly, causing two bugs: 1. `new mode` lines were not recognized as extended headers. The ExtendedHeader constants included `Old: 'old'` which matches `old mode ...`, but only had `NewFile: 'new file'` for new-prefixed headers. Since `'new mode ...'` does not start with `'new file'`, `parseExtendedHeader` returned null, breaking the extended header loop prematurely. 2. When `parseFileChange` returned undefined (due to unrecognized headers and no matching return conditions), `parseFileChanges` used `break` instead of `continue`, causing ALL subsequent files in the diff to be silently dropped. Fixes: - Add `NewMode: 'new mode'` to ExtendedHeader constants - Handle mode-only changes (no --- /+++ markers, no chunks) by falling back to the comparison line path - Change `parseFileChanges` to skip unparseable entries instead of aborting the entire parse Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Owner
|
@jkoppel Hello, thank you. This project has not been properly handling old mode and new mode. I think it would be good to output the changes in old and new mode as part of the parse results. What do you think? I created a PR to address this issue based on your commit. |
Contributor
Author
|
Sounds like a great idea @yeonjuan ! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Files with
old mode/new modeextended headers (e.g.chmod +xchanges) are not parsed correctly, causing two bugs:new modelines are not recognized as extended headers. TheExtendedHeaderconstants includeOld: 'old'which matchesold mode ..., but only haveNewFile: 'new file'for new-prefixed headers. Since'new mode ...'does not start with'new file',parseExtendedHeaderreturnsnull, breaking the extended header loop prematurely.All subsequent files are dropped. When
parseFileChangereturnsundefined(due to unrecognized headers and no matching return conditions),parseFileChangesusesbreakinstead of advancing past the problematic entry, causing ALL subsequent files in the diff to be silently dropped.Reproduction
Fix
NewMode: 'new mode'toExtendedHeaderconstants sonew modelines are properly recognizedparseFileChangefor files that have only extended headers (like mode changes) but no---/+++markers or chunks — returns aChangedFilewith the path from the comparison input lineparseFileChangesto skip unparseable entries (continue) instead of aborting the entire parse (break), so one unparseable file doesn't cause all subsequent files to be lostTests
Added 3 new test cases:
old mode 100644→new mode 100755)All existing tests continue to pass.