Skip to content

Conversation

@MirrorDNA-Reflection-Protocol

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_header regex 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_prefix verifies parsing works with c/ and w/ prefixes
  • All existing diff tests pass (except one pre-existing failure on main unrelated to this change)

References

Fixes gitpython-developers#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.

Changes:
- Update re_header regex to accept [abciwoh]/ prefixes
- Update decode_path() assertion to accept all valid mnemonic prefixes
- Add test case for mnemonicPrefix-style diffs
- Remove whitespace from blank lines in docstrings (ruff W293)
- Use !r format specifier for bytes in f-string (mypy str-bytes-safe)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

gitconfig: mnemonicPrefix conflict with create_patch

1 participant