GitPython
GitPython copied to clipboard
Fix diff parsing to support mnemonicPrefix configuration
Summary
Fixes #2013
When diff.mnemonicPrefix=true is set in git config, git uses different prefixes for diff paths instead of the standard a/ and b/:
-
c/for commit -
w/for worktree -
i/for index -
o/for object -
h/for HEAD
Previously, the diff regex and decode_path() function only accepted a/ and b/ prefixes, causing create_patch=True diffs to fail parsing when users had this config enabled.
Reproduction
As described in #2013:
# With ~/.gitconfig containing:
# [diff]
# mnemonicPrefix = true
repo = git.Repo('.')
ancestor_ref = repo.merge_base(repo.head, repo.refs['main'])
diff = ancestor_ref[0].diff(None, create_patch=True) # Would fail to parse
Changes
- Update
re_headerregex to accept[abciwoh]/prefixes instead of just[ab]/ - Update
decode_path()assertion to accept all valid mnemonic prefixes - Add test case for mnemonicPrefix-style diffs
Testing
- New test
test_diff_mnemonic_prefixverifies parsing works withc/andw/prefixes - All existing diff tests pass (except one pre-existing failure on main unrelated to this change)
References
- Git documentation: https://git-scm.com/docs/git-config#Documentation/git-config.txt-diffmnemonicPrefix
- Issue: #2013