fix(diff): read the index line after a dissimilarity index by JROtto5 · Pull Request #2353 · gitpython-developers/GitPython
Repository navigation
fix(diff): read the index line after a dissimilarity index - #2353
Merged
Byron merged 1 commit into gitpython-developers:main from JROtto5:fix/diff-dissimilarity-index Nov 23, 2026
Merged
fix(diff): read the index line after a dissimilarity index #2353 Byron merged 1 commit into gitpython-developers:main from JROtto5:fix/diff-dissimilarity-index
Conversation
JROtto5 commented Nov 23, 2026
Copy link Copy Markdown
Contributor
I am a Claude (Opus 5.5) agent working through the contributor's account.
Continuing the comparison of GitPython's parsers with what a current Git (2.56) prints, this time the patch header in Diff._index_from_patch_format. With B=True (git diff -B), a file that Git reports as rewritten came back with a_blob and b_blob set to None, and with no modes either when the mode had not changed. The same diff without -B has them. Other files in a -B diff are not affected.
For a broken pair Git writes dissimilarity index N% between the mode lines and the index line. re_header has no group for that line, and every group after it is optional, so the match ends there and the index line is never read. The hunks are still parsed, so nothing warns.
Accept the line, in the place Git writes it, before the index line.
Validation on Linux, CPython 3.14.4, Git 2.56.0:
- The new fixture is real
git diff -B --full-indexoutput for two rewritten files, one with a mode change and one without.test_diff_with_dissimilarity_indexfails on the originaldiff.py(a_blobisNone) and passes with the change. commit.diff(None, create_patch=True, B=True)on a real repository with the same two files: before, both had no blobs and the unchanged-mode file had no modes; after, both have the right blob ids and modes.- Complete test suite with the default backend: 2302 passed, 60 skipped, 1 xfailed.
test/test_diff.pyalso passes (51) withGIT_PYTHON_BACKEND=gix. - Ruff check and format pass.
Not run: mypy, the complete suite with the gix backend, other platforms and Python versions.
fix(diff): read the index line after a dissimilarity index
5ffee6c
With `-B`, Git writes `dissimilarity index N%` for a rewritten file, between the mode lines and the `index` line. `re_header` has no group for it, so the match stopped there: for a rewritten file `a_blob` and `b_blob` came back as `None`, and so did `a_mode` and `b_mode` when the mode had not changed (Git then puts it on the `index` line). The hunks were still read. Other files in the same `-B` diff were not affected. Accept the line, in the place Git writes it, before the `index` line. The new fixture is real `git diff -B --full-index` output for two rewritten files, one with a mode change and one without. `test_diff_with_dissimilarity_index` fails without this change. Agent-Model: claude-opus-5-5Byron merged commit
029964a
into
gitpython-developers : main
Nov 23, 2026
64 checks passed
JROtto5
mentioned this pull request
Nov 24, 2026
fix(submodule): resolve branch = . when update() clones a submodule
#2362
Merged
Sign up for free
to join this conversation on GitHub .
Already have an account?
Sign in to comment