Skip to content

Commit dc544f3

Browse files
codexByron
authored andcommitted
fix(gix): preserve stored commit identity text
Git 2.54 preserves the spaces inside a stored email address. GixPython 0.4.0 trims those spaces in its commit author and committer accessors. The accepted trailing-date prefix exposed that difference. Check the native identity against the raw header and retain the existing CLI path when the comparison fails. The regression covers author and committer whitespace and verifies that the native tagger already preserves it. The commit test file passed on both backends. Agent-Model: unknown
1 parent 132d912 commit dc544f3

4 files changed

Lines changed: 28 additions & 5 deletions

File tree

‎doc/gix-backend.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,6 +1016,7 @@ identify the historical fixture where needed.
10161016
| GIX-40 | Bug (open) | With Git 2.54.0 and GixPython 0.4.0, `gix-backend.sh embedded_status_uses_git_diff_policy` tracks a gitlink without a `.gitmodules` entry. An untracked file in its checkout leaves `git diff --raw` empty, but native configured status reports a `SubmoduleModification` with `superproject_configuration` false. Both report changes to tracked files in the embedded checkout. The fixture covers SHA-1 and SHA-256. | Expose Git's diff ignore policy for embedded repositories. `Repo.is_dirty()` uses Git when native worktree status reports a modification in an embedded repository. |
10171017
| GIX-41 | Bug (open) | With Git 2.54.0 and GixPython 0.4.0, `tree-modes.sh` writes an entry with either an empty mode field or the literal `0`. Both are decoded by `Tree.iter()` as mode zero and kind `commit`. Git rejects the empty field with `malformed mode in tree entry` and lists the literal zero as a gitlink. `test_ambiguous_tree_entry_mode_uses_git` verifies both results for SHA-1 and SHA-256. | Reject a missing mode or expose the distinction between a missing mode and an encoded zero. `_ls_tree()` defers mode zero to Git for validation and formatting. |
10181018
| GIX-42 | Bug (open) | With Git 2.54.0 and GixPython 0.4.0, `commit.sh negative-date` stores `-1 +0200 1700000000 -0500` in the author, committer and tagger identities. Git's `split_ident_line()` requires unsigned timestamp digits, so `git show --format=%ad --date=raw` reports no date and GitPython's CLI path returns `(0, 0)`. Native signature accessors expose `(-1, +7200)` as seconds and offset east of UTC. | Provide Git-compatible negative timestamp handling. `object_metadata()` retains CLI for negative dates. `test_deserialization_negative_timestamp_matches_git` verifies both object kinds. |
1019+
| GIX-43 | Bug (open) | With Git 2.54.0 and GixPython 0.4.0, `commit.sh spaced-email` stores spaces inside the email brackets ahead of a date with trailing fields. Git's `%ae` and `%ce` preserve these bytes, but native commit author and committer accessors trim them. The native tagger accessor preserves the spaces. | Expose a signature identity that preserves the stored fields with Git-compatible delimiters. `object_metadata()` uses the existing CLI fallback if the native identity fails the raw header comparison. `test_deserialization_preserves_email_whitespace` verifies author, committer and tagger properties. |
10191020

10201021
GIX-14 also covers configured worktree symlink resolution. On macOS with
10211022
GixPython 0.3.0, CPython 3.12.14 and Git 2.54.0, set a submodule's

‎git/_backend.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,11 @@ def object_metadata(command: Any, oid: str, kind: str) -> Any:
257257
if signature is not None:
258258
if signature.time.seconds < 0:
259259
raise _Unsupported("negative signature timestamp (GIX-42)")
260+
identity, _, date = raw.rpartition(b">")
261+
if b">" in signature.email or identity != signature.name + b" <" + signature.email:
262+
raise _Unsupported("signature identity differs from raw header (GIX-43)")
260263
# Gix can decode a short offset such as +020 as UTC.
261-
date = raw.rpartition(b">")[2].replace(b" -0000", b" +0000", 1)
264+
date = date.replace(b" -0000", b" +0000", 1)
262265
if not (date + b" ").startswith(b" " + _date(signature) + b" "):
263266
raise _Unsupported("signature date differs from raw header (GIX-38)")
264267
except _Unsupported as exc:

‎test/test_commit.py‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,23 @@ def test_deserialization_reads_date_after_email(self):
706706
key = (kind + ".decode", "native")
707707
self.assertEqual(_backend.statistics().get(key, 0), before.get(key, 0) + 1)
708708

709+
def test_deserialization_preserves_email_whitespace(self):
710+
with fixture_repo("commit.sh", "spaced-email") as repo:
711+
root = Path(repo.working_dir).parent
712+
oid = (root / "object-id").read_text().strip()
713+
tag_oid = (root / "tag-id").read_text().strip()
714+
self.assertEqual(repo.git.show("-s", "--format=[%ae][%ce]", oid), "[ a@example.com ][ c@example.com ]")
715+
before = _backend.statistics()
716+
commit = Commit(repo, bytes.fromhex(oid))
717+
self.assertEqual((commit.author.email, commit.committer.email), (" a@example.com ", " c@example.com "))
718+
self.assertEqual(TagObject(repo, bytes.fromhex(tag_oid)).tagger.email, " t@example.com ")
719+
if _backend.name == "gix":
720+
for key in (
721+
("commit.decode", "CLI: signature identity differs from raw header (GIX-43)"),
722+
("tag.decode", "native"),
723+
):
724+
self.assertEqual(_backend.statistics().get(key, 0), before.get(key, 0) + 1)
725+
709726
def test_deserialization_negative_timestamp_matches_git(self):
710727
with fixture_repo("commit.sh", "negative-date") as repo:
711728
root = Path(repo.working_dir).parent

‎tests/fixtures/commit.sh‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,21 +57,23 @@ case "$1" in
5757
raw)
5858
git hash-object --literally -w -t commit "$2" > ../object-id
5959
;;
60-
trailing-date|zero-offset|short-offset|negative-date)
60+
trailing-date|zero-offset|short-offset|negative-date|spaced-email)
6161
date='1112591163 +0200 1700000000 -0500'
6262
if [ "$1" = zero-offset ]; then date='1112591163 -0000'; fi
6363
if [ "$1" = short-offset ]; then date='1112591163 +020'; fi
6464
if [ "$1" = negative-date ]; then date='-1 +0200 1700000000 -0500'; fi
65+
space=''
66+
if [ "$1" = spaced-email ]; then space=' '; fi
6567
tree=$(git mktree </dev/null)
6668
{
6769
printf 'tree %s\n' "$tree"
68-
printf 'author A <a@example.com> %s\n' "$date"
69-
printf 'committer C <c@example.com> %s\n' "$date"
70+
printf 'author A <%sa@example.com%s> %s\n' "$space" "$space" "$date"
71+
printf 'committer C <%sc@example.com%s> %s\n' "$space" "$space" "$date"
7072
printf '\nmessage\n'
7173
} | git hash-object --literally -w -t commit --stdin > ../object-id
7274
{
7375
printf 'object %s\ntype commit\ntag v1\n' "$(cat ../object-id)"
74-
printf 'tagger T <t@example.com> %s\n' "$date"
76+
printf 'tagger T <%st@example.com%s> %s\n' "$space" "$space" "$date"
7577
printf '\nmessage\n'
7678
} | git hash-object --literally -w -t tag --stdin > ../tag-id
7779
git update-ref refs/tags/v1 "$(cat ../tag-id)"

0 commit comments

Comments
 (0)