Skip to content

Commit 16084b6

Browse files
committed
fix(gix): use Git for signed and line-feed-only tag messages
On the Gix backend, `TagObject._set_cache_()` builds `TagObject.message` by joining the `message` and `signature` that `_backend.object_metadata()` returns from GixPython's `Tag.decode()`. GixPython 0.3.0 omits the line feed that separates a message from a trailing `PGP SIGNATURE`, `PGP MESSAGE`, `SIGNED MESSAGE` or `SSH SIGNATURE` armor block, so every signed tag lost it. For a tag made with `git tag -s -m 'Release 1.0'` and SSH signing, `git cat-file tag` and the CLI backend have `Release 1.0\n-----BEGIN SSH SIGNATURE-----...`, while the Gix backend reported `Release 1.0-----BEGIN SSH SIGNATURE-----...`. The last message line runs into the armor header, so code that separates the signature at its armor line no longer finds it. The two fields cannot be joined back in Python: a body that starts with the armor and one that starts with an empty line before it decode to the same `message` and `signature`. Gix also adds a line feed to a body of only line feeds, so the body `\n\n` gave a `TagObject.message` of `\n\n` instead of `\n`. The adapter now selects the CLI path when Gix splits off a signature or reports a message of two or more line feeds and nothing else. The guard only chooses the fallback and produces no values. Unsigned tags and empty messages stay native: an empty body decodes as one line feed, which the existing final line-feed trim already removes. The mismatch is recorded as GIX-46 in `doc/gix-backend.md` (GIX-36 is used by the pending tree-mode change); this guard does not close it. Validation on macOS arm64 with CPython 3.13.17, Git 2.54.0 and GixPython 0.3.0: - `test_tag_message_matches_git`, using the new `tag-message` case in `tests/fixtures/refs.sh`, fails for all four variants with SHA-1 and SHA-256 on the Gix backend before the change and passes on both backends after it. - An SSH-signed tag from `git tag -s` and armor-shaped probes (`PGP MESSAGE`, `SIGNED MESSAGE`, a `CERTIFICATE` block, armor text inside a line, empty and unsigned bodies) give identical `TagObject.message` values on both backends. The certificate, inline, empty and unsigned cases stay native. - `test_tag_without_tagger_initializes_all_metadata`, which forbids CLI calls for unsigned and empty tag messages, still passes on Gix. - Full suite with `-m "not net"`: 2093 passed, 154 skipped, 1 xfailed on the CLI backend; 2196 passed, 51 skipped, 1 xfailed on the Gix backend, where native tag decoding still serves 34 calls and the new fallback serves only the 8 calls from the new test. - Ruff check and format, mypy, shellcheck and `git diff --check` pass.
1 parent 9232dc5 commit 16084b6

4 files changed

Lines changed: 47 additions & 0 deletions

File tree

‎doc/gix-backend.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ Commit metadata uses `Repository.find_commit().decode()` plus structured
151151
`Commit.author()`/`committer()` signatures. Tag metadata uses
152152
`Repository.find_tag().decode()` and `Tag.tagger()`. A missing native tagger maps
153153
to GitPython's empty actor and zero date/offset; tag reads remain native.
154+
Tags with a signature block or a body of only line feeds use `git cat-file`
155+
because the decoded message does not delimit the body as Git does (GIX-46).
154156
Decoded extra headers retain
155157
`gpgsig`. Raw Gix object bytes are used only for object streams. If repository
156158
capabilities require CLI fallback, metadata uses `git cat-file`: general formatted
@@ -1019,6 +1021,7 @@ identify the historical fixture where needed.
10191021
| 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. |
10201022
| GIX-44 | Bug (open) | With Git 2.54.0 and GixPython 0.3.0, the `branch-dot-alias` case of `submodule-cases.sh` sets `HEAD` to `refs/heads/dev`, which points to `refs/heads/master`. `Repository.head_name()` and `Repository.head_ref().name()` return `refs/heads/dev`. `git symbolic-ref HEAD` returns `refs/heads/master`, and `git submodule update --remote` selects `origin/master` for `branch = .`. `test_update_to_latest_revision_follows_superproject_branch_alias` verifies branch selection on clone and later updates. Redirect `dev` to `refs/heads/missing` and Git returns that terminal name, while `Reference.follow_to_object()` raises a missing-ref error. | Expose the terminal symbolic target with Git-compatible handling of unborn, detached and invalid references. `Submodule._branch_for_update()` uses recursive `git symbolic-ref --quiet -- HEAD` through the CLI fallback. |
10211023
| GIX-45 | Bug (open) | Git 2.54.0 `submodule update --remote --no-fetch` rejects a bare `branch` key in `.gitmodules` with `missing value for 'submodule.module.branch'`, including before or after `branch = dev`. In GixPython 0.3.0 and 0.4.0, `ModulesFile.from_bytes()` accepts the bare key and `ModulesFile.branch()` returns `None` for an absent or single bare key. `ConfigFile.boolean()` distinguishes these two inputs with `None` and `True`, respectively. When the bare key precedes `branch = dev`, both `ModulesFile.branch().name_bytes()` and `ConfigFile.string()` return `b"dev"`. For an explicit `branch =` with an `origin` remote, Git attempts to resolve `refs/remotes/origin/`, `ModulesFile.branch().name_bytes()` returns `b"HEAD"`, and `ConfigFile.string()` returns `b""`. | Reject valueless branches in a Git-compatible mode or expose all raw values, including implicit ones. `submodule_config()` falls back to the Git config reader for possible bare `branch` keys and uses `ConfigFile.string()` for assigned values. `test_valueless_branch_is_invalid` covers listing and rereads with a single bare key and one followed by an assignment. |
1024+
| GIX-46 | Bug (open) | With Git 2.54.0 and GixPython 0.3.0, `Tag.decode()` omits the line feed that separates a tag message from a trailing `PGP SIGNATURE`, `PGP MESSAGE`, `SIGNED MESSAGE` or `SSH SIGNATURE` armor block. A tag made with `git tag -s -m 'Release 1.0'` and `gpg.format=ssh` decodes to the message `Release 1.0` and a signature starting at `-----BEGIN SSH SIGNATURE-----`, while `git cat-file tag` stores `Release 1.0\n` before the armor; joining both fields lost that line feed in `TagObject.message`. A body that starts with the armor and one that starts with an empty line before it therefore decode to the same fields. A body of only line feeds gains one: `\n\n` decodes as `\n\n\n` and an empty body as `\n`. The `tag-message` read-only `refs.sh` fixture in `test_tag_message_matches_git` reproduces the signed, empty-line and line-feed cases for SHA-1 and SHA-256. | Report a message and signature that reproduce the tag body, including the separating line feed, and report bodies of only line feeds unchanged, at least in a Git-strict decoding mode. `object_metadata()` selects CLI when Gix splits off a signature or reports a message of two or more line feeds and nothing else; an empty body decoded as `\n` already yields GitPython's empty message after its final line-feed trim. This adapter guard does not close the upstream compatibility bug. |
10221025

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

‎git/_backend.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,12 @@ def object_metadata(command: Any, oid: str, kind: str) -> Any:
240240
"committer": obj.committer(),
241241
}
242242
else:
243+
# Gix omits the line feed before a signature, so a body starting with the
244+
# signature decodes like one starting with an empty line, and adds a line
245+
# feed to a body of only line feeds (GIX-46). An empty body decodes as one
246+
# line feed, which TagObject's final line-feed trim already removes.
247+
if data.signature is not None or (len(data.message) > 1 and not data.message.strip(b"\n")):
248+
raise _Unsupported("tag message boundaries (GIX-46)")
243249
result = {
244250
"target": data.target.decode("ascii"),
245251
"target_kind": data.target_kind,

‎test/test_refs.py‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,31 @@ def test_tag_without_tagger_initializes_all_metadata(object_format, message):
194194
assert tag.message == message
195195

196196

197+
@pytest.mark.parametrize("object_format", ["sha1", "sha256"])
198+
@pytest.mark.parametrize(
199+
"variant, body",
200+
[
201+
pytest.param(variant, body, id=variant)
202+
for variant, body in (
203+
("pgp", "release\n-----BEGIN PGP SIGNATURE-----\nc2ln\n-----END PGP SIGNATURE-----\n"),
204+
("ssh", "release\n-----BEGIN SSH SIGNATURE-----\nc2ln\n-----END SSH SIGNATURE-----\n"),
205+
("empty-line", "\n-----BEGIN PGP SIGNATURE-----\nc2ln\n-----END PGP SIGNATURE-----\n"),
206+
("line-feeds", "\n\n"),
207+
)
208+
],
209+
)
210+
def test_tag_message_matches_git(object_format, variant, body):
211+
with fixture_repo("refs.sh", "tag-message", object_format, variant) as repo:
212+
oid = (Path(repo.working_tree_dir).parent / "tag-id").read_text().strip()
213+
raw = repo.git.cat_file("tag", oid, stdout_as_string=False, strip_newline_in_stdout=False)
214+
assert raw.partition(b"\n\n")[2] == body.encode()
215+
before = _backend.statistics()
216+
assert TagObject(repo, bytes.fromhex(oid)).message == body[:-1]
217+
if _backend.name == "gix":
218+
key = ("tag.decode", "CLI: tag message boundaries (GIX-46)")
219+
assert _backend.statistics().get(key, 0) == before.get(key, 0) + 1
220+
221+
197222
@pytest.mark.parametrize("object_format", ["sha1", "sha256"])
198223
def test_head_rename_retains_literal_prefixed_branch_name(object_format):
199224
with fixture_repo("refs.sh", "rename-prefixed", object_format, write=True) as repo:

‎tests/fixtures/refs.sh‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,19 @@ case "$1" in
3030
fi
3131
} | git hash-object -w -t tag --literally --stdin >../tag-id
3232
;;
33+
tag-message)
34+
{
35+
printf 'object %s\ntype commit\ntag v1\n' "$(git rev-parse HEAD)"
36+
printf 'tagger T <t@example.com> 1700000000 +0000\n\n'
37+
case "$3" in
38+
pgp) printf 'release\n-----BEGIN PGP SIGNATURE-----\nc2ln\n-----END PGP SIGNATURE-----\n' ;;
39+
ssh) printf 'release\n-----BEGIN SSH SIGNATURE-----\nc2ln\n-----END SSH SIGNATURE-----\n' ;;
40+
empty-line) printf '\n-----BEGIN PGP SIGNATURE-----\nc2ln\n-----END PGP SIGNATURE-----\n' ;;
41+
line-feeds) printf '\n\n' ;;
42+
*) exit 1 ;;
43+
esac
44+
} | git hash-object -w -t tag --literally --stdin >../tag-id
45+
;;
3346
rename-prefixed)
3447
git branch topic
3548
printf 'second\n' >> file.txt

0 commit comments

Comments
 (0)