Skip to content

Commit 6f7a070

Browse files
codexByron
authored andcommitted
fix(gix): defer ambiguous zero tree modes to Git
GixPython 0.4.0 decodes a missing mode and a literal zero as the same gitlink. Git 2.54 rejects the missing mode but accepts the literal zero. Send native zero modes through Git before formatting tree entries so malformed input raises the Git diagnostic. The tree fixture covers both spellings and both object formats. The focused native tree and object tests passed. Agent-Model: unknown
1 parent 86d0f88 commit 6f7a070

4 files changed

Lines changed: 33 additions & 5 deletions

File tree

‎doc/gix-backend.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,6 +1014,7 @@ identify the historical fixture where needed.
10141014
| GIX-38 | Bug (open) | With Git 2.54.0 and GixPython 0.4.0, the `commit.sh short-offset` fixture stores `1112591163 +020` in an identity. `git show -s --format=%ad --date=raw` reports `1112591163 +0020`, while `Commit.author()` reports an offset of zero. A separate probe with `+0299` preserves that spelling in Git but renders as `+0339` from the native offset in seconds. | Expose Git-compatible interpretation of short offsets and a way to preserve the stored offset spelling. `object_metadata()` accepts native dates when their formatted prefix matches the raw identity and otherwise keeps the existing CLI fallback. `test_deserialization_short_offset_matches_git` verifies the fallback returns the 20-minute offset. |
10151015
| GIX-39 | Bug (open) | On Git 2.54.0, `git rev-parse --verify HEAD@{never}` rejects the date. GixPython 0.4.0's `Repository.rev_parse_single()` returns the oldest commit. With reflog entries 80, 52, 49, 40, 3 and 0 hours old, Git also selects the 80-hour entry for `HEAD@{2days3hours}`, while Gix selects the 52-hour entry. | Match Git's approxidate grammar and invalid-date handling. `_check_revision_grammar()` retains CLI for textual selectors. `test_rev_parse_reflog_selectors` covers a rejected date, an accepted date and ordinary reflog selectors. |
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. |
1017+
| 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. |
10171018

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

‎git/_backend.py‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -335,10 +335,14 @@ def _ls_tree(repo: Any, args: List[str], kwargs: Dict[str, Any]) -> bytes:
335335
if len(args) != 3 or args[:2] != ["-z", "--full-tree"]:
336336
raise _Unsupported("tree options")
337337
with repo.find_tree(_oid(repo, args[2])).iter() as entries:
338-
return b"".join(
339-
b"%s %s\t%s\0" % (_LS_TREE_MODES[entry.kind()], str(entry.id()).encode("ascii"), entry.filename())
340-
for entry in entries
341-
)
338+
records = []
339+
for entry in entries:
340+
if entry.mode() == 0:
341+
raise _Unsupported("ambiguous zero tree entry mode (GIX-41)")
342+
records.append(
343+
b"%s %s\t%s\0" % (_LS_TREE_MODES[entry.kind()], str(entry.id()).encode("ascii"), entry.filename())
344+
)
345+
return b"".join(records)
342346

343347

344348
def check_ref_name(name: str) -> Any:

‎test/test_gix_backend.py‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,25 @@ def test_native_tree_entry_modes_match_git(object_format, entry_types):
276276
assert [(entry.path, entry.mode) for entry in tree] == expected
277277

278278

279+
@pytest.mark.parametrize("object_format", ["sha1", "sha256"])
280+
@pytest.mark.parametrize("entry_types", ["missing-mode", "zero-mode"])
281+
def test_ambiguous_tree_entry_mode_uses_git(object_format, entry_types):
282+
with fixture_repo("tree-modes.sh", object_format, entry_types) as repo:
283+
oid = (Path(repo.working_dir).parent / "tree-id").read_text().strip()
284+
tree = Tree(repo, bytes.fromhex(oid), path="")
285+
before = _backend.statistics()
286+
if entry_types == "missing-mode":
287+
with pytest.raises(GitCommandError, match="malformed mode"):
288+
repo.git.ls_tree(oid)
289+
with pytest.raises(GitCommandError, match="malformed mode"):
290+
list(tree)
291+
else:
292+
assert "160000 commit" in repo.git.ls_tree(oid)
293+
assert tree["module"].mode == 0o160000
294+
key = ("ls_tree", "CLI: ambiguous zero tree entry mode (GIX-41)")
295+
assert _backend.statistics().get(key, 0) == before.get(key, 0) + 1
296+
297+
279298
def test_native_metadata_paths_match_git_in_each_worktree(repo):
280299
tmp_path = Path(repo.working_dir).parent
281300
linked_path = tmp_path / "linked"

‎tests/fixtures/tree-modes.sh‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ write_entry () {
1010
}
1111
{
1212
write_entry 100700 executable "$blob"
13-
if test "$2" = gitlink; then write_entry 140000 module "$commit"; fi
13+
case "$2" in
14+
gitlink) write_entry 140000 module "$commit" ;;
15+
missing-mode) write_entry '' module "$commit" ;;
16+
zero-mode) write_entry 0 module "$commit" ;;
17+
esac
1418
write_entry 120777 symlink "$blob"
1519
} | git -C repo hash-object --literally -w -t tree --stdin >tree-id

0 commit comments

Comments
 (0)