Repository navigation
fix(diff): request a/ and b/ header prefixes for patch diffs - #2371
Closed
qianeric-backup wants to merge 1 commit into
Closed
qianeric-backup wants to merge 1 commit into
qianeric-backup wants to merge 1 commit into
Conversation
qianeric-backup
marked this pull request as ready for review
November 27, 2026 15:46
Document that diff.noprefix, diff.srcPrefix and diff.dstPrefix no longer make Diffable.diff(..., create_patch=True) return an empty DiffIndex.
qianeric-backup
force-pushed
the
diff-patch-header-prefixes
branch
from
November 27, 2026 15:47
db24842 to
27c8c82
Compare
Member
|
I am closing this PR as it violates the contributing guideline: fixes must refer to the downstream issue that motivates the fix. PS: If GitPython is too buggy and annoying to contribute to, consider trying its successor, GixPython. The underlying engine, Gitoxide has no restrictions on contributions either. |
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.
With
diff.noprefix=truein the repository config,create_patch=Truereturns nothing at all for index and worktree changes:No exception, no warning — an empty
DiffIndexfor a worktree that has changes.git diff-tree(the commit-to-commit path) is unaffected, so the two documented shapes disagree with each other.The cause is the header the patch parser requires.
diff.noprefixmakesgit diffemitdiff --git foo.txt foo.txt, andDiff.re_headeronly acceptsa/andb/:decode_pathstates the same requirement directly:assert path.startswith(b"a/") or path.startswith(b"b/").Four lines below the affected branch, the same function already deals with exactly this class of problem for a different key:
diff.mnemonicPrefixrewrites the prefixes toi/,w/,c/,o/— same breakage, handled.diff.noprefix,diff.srcPrefixanddiff.dstPrefixwere not, and none of them is in the_configallowlist ingit/cmd.py, so they cannot be passed that way.Changes
Pass the prefixes on the command line rather than adding three more
-coverrides:Command-line options take precedence over all four config keys, and this needs no change to the
_configallowlist. A caller who asks for something else explicitly (no_prefix=True,src_prefix=...) still gets it, because those are appended after and win.doc/source/changes.rstentry.Verification
Three parametrized cases, one per config key (
diff.noprefix,diff.srcPrefix,diff.dstPrefix), each run against all three backends (default,GIT_PYTHON_BACKEND=cli,GIT_PYTHON_BACKEND=gix):test/test_diff.pymain52 passedmain+ new tests,git/diff.pyunchanged3 failed, 52 passed55 passedThe failures are
ValueError: not enough values to unpack (expected 1, got 0)— the emptyDiffIndex. All three backends fail identically; the gix backend raises_Unsupportedforpatch=Trueand always falls back to CLI parsing, so the defect is backend-independent.Full suite (
pytest test -m 'not net' --ignore=test/performance):2349 passedbefore and after,comm -3over theFAILEDlines empty, and2352with the new cases. The one pre-existing failure,test_shared_fixture_works_without_checkout_history, is an environment artefact — that test filters the child environment down toPATHand friends, so the gix package installed onPYTHONPATHis not visible to it — and fails identically onmain.Twelve legal calls (
index.diff(None),index.diff("HEAD"),commit.diff(),commit.diff("HEAD~1"),commit.diff(NULL_TREE), each with and withoutcreate_patch) against a two-commit repo containing a rename, a deletion, an addition, a mode change, a binary file, a symlink, a staged change, an untracked file and a subdirectory produce byte-identical output before and after (cmp, 2706 bytes).ruff 0.17.2(the pinned rev)checkandformat --checkpass on the changed files.Note this needs git ≥ 2.52 to run the suite, so I built 2.56.1 locally rather than relying on the system 2.43.