From 71ebaa7a64b2401ff9e5e113fab7d594ef7e582c Mon Sep 17 00:00:00 2001 From: Keerthana KT Date: Sun, 15 Nov 2026 11:18:23 +0530 Subject: [PATCH 1/3] fix(gix): use Git for tree entries whose modes Git canonicalizes On the Gix backend, `Tree._set_cache_()` lists a tree through the native `_backend._ls_tree()` adapter, which reports `TreeEntry.mode()` and `TreeEntry.kind()` from GixPython 0.3.0. Gix keeps the mode as stored, while Git canonicalizes it when it reads a tree (`canon_mode`), so `git ls-tree`, `git read-tree` and checkout use `100755` for `100700`, `120000` for `120777` and `160000` for any mode whose type is not a regular file, symbolic link or directory. Tree contents are untrusted repository content, and `git fsck` reports such trees only as `badFilemode` warnings, so default transfers accept them. On the Gix backend: - an entry with mode `120777` had `Blob.mode == 0o120777`, so a check against `Blob.link_mode` treated a path that Git checks out as a symbolic link as a regular file; `100700` likewise did not match `Blob.executable_mode`; - a `140000` entry, which Git reads as a gitlink, was reported as a tree with mode `0o40000`, so `Tree.traverse()` and `tree / "sub/..."` listed the contents of an object Git never checks out; - other noncanonical gitlink modes, such as `170000`, made iteration raise `TypeError`. The CLI backend already reported Git's modes. GixPython exposes neither the modes Git reads nor the raw mode bytes, so the adapter now selects the CLI path unless every native mode is one Git reports and the tree's bytes, written to `Repository.with_object_memory()`, re-encode to the same object ID. The second check catches the `140000` case, whose native mode already looks canonical; it follows the existing GIX-5 round-trip preflight in `_hash_object()`. The guard only chooses the fallback and produces no values. Canonical trees stay native. The mismatch is recorded as GIX-36 in `doc/gix-backend.md`; this guard does not close it. Validation on macOS with CPython 3.12, Git 2.54.0 and GixPython 0.3.0: - `test_tree_entry_modes_match_git`, using the new `tree-modes.sh` fixture, compares each entry with `git ls-tree`; it fails for all six cases (three modes, SHA-1 and SHA-256) on the Gix backend before the change and passes on both backends after it. - A sweep of 99 literal tree modes against `git ls-tree` found a mode or kind difference for every mode Git canonicalizes, except the zero-padded `040000` and `0100644` spellings, which matched, and `10100644`, which Gix fails to decode and already sends to Git. - Full suite: 2105 passed, 155 skipped, 1 xfailed on the CLI backend; 2208 passed, 52 skipped, 1 xfailed on the Gix backend. - Ruff check and format, mypy and `git diff --check` pass; shellcheck was not available locally. Agent-Model: claude-opus-5-5 --- doc/gix-backend.md | 3 ++- git/_backend.py | 11 ++++++++++- test/test_tree.py | 14 +++++++++++++- tests/fixtures/tree-modes.sh | 16 ++++++++++++++++ 4 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 tests/fixtures/tree-modes.sh diff --git a/doc/gix-backend.md b/doc/gix-backend.md index 7861054f8..909b8c707 100644 --- a/doc/gix-backend.md +++ b/doc/gix-backend.md @@ -367,7 +367,7 @@ and predate the current fallback; they do not establish native coverage. | Standalone discovery helpers | Native storage directories and gitfiles reopened at their canonical native Git directory | Rejected candidates and the same layout/environment guards as `Repo` opening; GIX-14 | | `Repo.rev_parse`, `rev_parse` metadata queries | Revision lookup, common directory, object format, bare flag, worktree root, fixed `modules`/`COMMIT_EDITMSG` locations | Repository-format validation, other metadata paths, symlinked metadata leaves, message searches and describe forms; GIX-1/14/17/22 | | Revision path/mode metadata | Native revision specification, including tree paths and index stages | Custom/sparse indexes, unsupported revision grammar or path normalization | -| Tree enumeration, `ls_tree` | Native tree entries with modes, names, and object IDs | Other command options | +| Tree enumeration, `ls_tree` | Native tree entries with modes, names, and object IDs | Other command options; entries with modes Git canonicalizes or that do not round-trip through native tree encoding; GIX-36 | | Reference object reads | One exact native lookup for direct, symbolic and absent references | Partial names and native decoding errors | | Reference-name validation | Native full-name validation without opening a repository | Standalone names outside the native grammar; GIX-20 | | Managed `symbolic_ref` | Nonrecursive target lookup | Mutation, command-level missing-reference diagnostics | @@ -991,6 +991,7 @@ identify the historical fixture where needed. | GIX-33 | Bug (open); missing exact-name mode | With Git 2.54.0 and GixPython 0.3.0, `exact-refs.sh sha1 files symbolic` makes `refs/tags/REBASE_HEAD` a symbolic ref to another tag while the root `REBASE_HEAD` is absent. `Repository.try_find_reference("REBASE_HEAD")` returns that tag; native `_symbolic_ref` formerly returned its target, whereas `git symbolic-ref --quiet --no-recurse -- REBASE_HEAD` exits 1. GitPython's root-reference object read consequently returned a commit through Gix and raised `ValueError` through CLI. SHA-256 reproduces the same mismatch. | Expose an exact-name lookup mode, including root references, whose absence and error behavior matches Git. `_symbolic_ref()` compares the native reference's name with the requested bytes and selects CLI for a lookalike. `test_missing_root_reference_does_not_follow_symbolic_lookalike_tag` verifies parity and forced CLI fallback. This adapter guard does not close the upstream compatibility bug. | | GIX-34 | Bug (open) | With Git 2.54.0 and GixPython 0.3.0, an author, committer or tagger line with fields after its time zone, such as `A 1112591163 +0200 1700000000 -0500`, decodes through `Commit.author()`/`committer()` and `Tag.tagger()` with the correct seconds but an offset of 0. Git reads only the first date and time zone after the last `>` (`split_ident_line`) and reports `1112591163 +0200` through `git show --format=%ad --date=raw` and `%(taggerdate:raw)`. `git fsck` reports `badTimezone` for such objects, but the default `transfer.fsckObjects=false` accepts them. The `trailing-date` read-only `commit.sh` fixture in `test_deserialization_reads_date_after_email` reproduces both object kinds. | Report the time zone Git reads for identity lines with trailing fields, or reject them consistently. `object_metadata()` selects CLI when the decoded signature does not reproduce the end of its raw header line. This adapter guard does not close the upstream compatibility bug. | | GIX-35 | Bug (open) | With Git 2.54.0 and GixPython 0.3.0, `ModulesFile.from_bytes()` accepts `.gitmodules` lines that Git rejects with `bad config line`, so `git submodule update --init` stops while `git fsck` reports only `gitmodulesParse`. A line holding more than one name is read as several settings: after `url = ../good`, `x url = ../evil` makes `url()` return `../evil` with `submodule..x` true, and `[submodule "module"] x url = ../evil` does the same on the header line. `br#anch = main` is read as an implicit `br` followed by a comment. The `submodule-rejected-lines.sh` read-only fixture in `test_submodule_configuration_rejects_lines_git_rejects` reproduces all three. | Reject the lines Git rejects, at least in a Git-strict parsing mode, with a typed error. `submodule_config()` selects CLI unless every line is blank, a comment, a bare submodule header or a single `key` or `key = value` setting, so Git's parser reports the error. This adapter guard does not close the upstream compatibility bug. | +| GIX-36 | Bug (open) | With Git 2.54.0 and GixPython 0.3.0, `Tree.iter()` reports tree entry modes as stored, while Git canonicalizes them when it reads a tree (`canon_mode`): `git ls-tree` and checkout use `100755` for `100700`, `120000` for `120777` and `160000` for every mode whose type is not a regular file, symbolic link or directory. `TreeEntry.mode()` returned `0o100700` and `0o120777`, so `Blob.mode` did not match `Blob.executable_mode` or `Blob.link_mode` for entries Git checks out as an executable or a symbolic link. A `140000` entry, which Git reads as a gitlink, is reported as a tree with mode `0o40000`, so GitPython listed the contents of an object Git never checks out; other noncanonical gitlink modes made tree iteration raise `TypeError`. `git fsck` reports these trees only as `badFilemode` warnings, so default transfers accept them. The `tree-modes.sh` read-only fixture in `test_tree_entry_modes_match_git` reproduces all three for SHA-1 and SHA-256. | Report the modes Git reads, at least in a Git-compatible mode, or expose the raw mode bytes. `_ls_tree()` selects CLI unless every native mode is one Git reports and the tree's bytes re-encode to the same object ID through the in-memory object database, so Git lists the entries. This adapter guard does not close the upstream compatibility bug. | GIX-14 also covers configured worktree symlink resolution. On macOS with GixPython 0.3.0, CPython 3.12.14 and Git 2.54.0, set a submodule's diff --git a/git/_backend.py b/git/_backend.py index 51d25c436..1e79cc4e6 100644 --- a/git/_backend.py +++ b/git/_backend.py @@ -314,7 +314,16 @@ def _rev_parse(repo: Any, args: List[str], kwargs: Dict[str, Any]) -> bytes: def _ls_tree(repo: Any, args: List[str], kwargs: Dict[str, Any]) -> bytes: if len(args) != 3 or args[:2] != ["-z", "--full-tree"]: raise _Unsupported("tree options") - with repo.find_tree(_oid(repo, args[2])).iter() as entries: + oid = _oid(repo, args[2]) + tree = repo.find_tree(oid) + # Native entries keep modes Git canonicalizes and read a 14xxxx gitlink as a + # tree (GIX-36); Git lists trees whose entries do not round-trip natively. + if repo.with_object_memory().write_object("tree", tree.data) != oid: + raise _Unsupported("tree entries Git canonicalizes (GIX-36)") + with tree.iter() as entries: + if any(entry.mode() not in _ENTRY_KINDS for entry in entries): + raise _Unsupported("tree entries Git canonicalizes (GIX-36)") + with tree.iter() as entries: return b"".join( b"%06o %s %s\t%s\0" % ( diff --git a/test/test_tree.py b/test/test_tree.py index 8d29319fb..192702a94 100644 --- a/test/test_tree.py +++ b/test/test_tree.py @@ -56,7 +56,19 @@ def test_invalid_tree_does_not_retain_partial_cache(object_format, invalid_posit list(tree) -def test_tree_modifier_orders_non_utf8_names_as_git_does(): +@pytest.mark.parametrize("object_format", ["sha1", "sha256"]) +@pytest.mark.parametrize("scenario", ["executable", "symlink", "gitlink"]) +def test_tree_entry_modes_match_git(object_format, scenario): + with fixture_repo("tree-modes.sh", object_format, scenario) as repo: + root = read_only_fixture("tree-modes.sh", object_format, scenario) + oid = (root / "tree-id").read_text().strip() + metadata, name = (root / "entries").read_text().rstrip("\n").split("\t") + mode, kind, entry_oid = metadata.split() + assert mode in ("100755", "120000", "160000") + tree = Tree(repo, bytes.fromhex(oid), path="") + assert [(entry.mode, entry.type, entry.hexsha, entry.path) for entry in tree] == [ + (int(mode, 8), "submodule" if kind == "commit" else kind, entry_oid, name) + ] with fixture_repo("tree-byte-order.sh") as repo: expected = (read_only_fixture("tree-byte-order.sh") / "order").read_bytes().split(b"\0")[:-1] tree = repo.head.commit.tree diff --git a/tests/fixtures/tree-modes.sh b/tests/fixtures/tree-modes.sh new file mode 100644 index 000000000..fe1938a85 --- /dev/null +++ b/tests/fixtures/tree-modes.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash +set -eu +git init --initial-branch=main --object-format="$1" repo +cd repo +blob=$(printf 'content\n' | git hash-object -w --stdin) +subtree=$(printf '100644 blob %s\tinner\n' "$blob" | git mktree) +case "$2" in +executable) entry="100700 exe" oid=$blob ;; +symlink) entry="120777 link" oid=$blob ;; +gitlink) entry="140000 sub" oid=$subtree ;; +esac +# git mktree only writes canonical modes, so write the legacy mode literally. +escaped=$(printf %s "$oid" | sed 's/../\\x&/g') +{ printf '%s\0' "$entry"; printf %b "$escaped"; } | + git hash-object -w -t tree --literally --stdin >../tree-id +git ls-tree "$(cat ../tree-id)" >../entries From 03827908b84ab53bc30689efa0f91a76638eb2cf Mon Sep 17 00:00:00 2001 From: Byron Date: Sun, 15 Nov 2026 13:02:49 +0100 Subject: [PATCH 2/3] review once again, keep only the reference to the gix bug, which will be fixed before the next GitPython release. --- git/_backend.py | 11 +---------- test/test_tree.py | 14 +------------- tests/fixtures/tree-modes.sh | 16 ---------------- 3 files changed, 2 insertions(+), 39 deletions(-) delete mode 100644 tests/fixtures/tree-modes.sh diff --git a/git/_backend.py b/git/_backend.py index 1e79cc4e6..51d25c436 100644 --- a/git/_backend.py +++ b/git/_backend.py @@ -314,16 +314,7 @@ def _rev_parse(repo: Any, args: List[str], kwargs: Dict[str, Any]) -> bytes: def _ls_tree(repo: Any, args: List[str], kwargs: Dict[str, Any]) -> bytes: if len(args) != 3 or args[:2] != ["-z", "--full-tree"]: raise _Unsupported("tree options") - oid = _oid(repo, args[2]) - tree = repo.find_tree(oid) - # Native entries keep modes Git canonicalizes and read a 14xxxx gitlink as a - # tree (GIX-36); Git lists trees whose entries do not round-trip natively. - if repo.with_object_memory().write_object("tree", tree.data) != oid: - raise _Unsupported("tree entries Git canonicalizes (GIX-36)") - with tree.iter() as entries: - if any(entry.mode() not in _ENTRY_KINDS for entry in entries): - raise _Unsupported("tree entries Git canonicalizes (GIX-36)") - with tree.iter() as entries: + with repo.find_tree(_oid(repo, args[2])).iter() as entries: return b"".join( b"%06o %s %s\t%s\0" % ( diff --git a/test/test_tree.py b/test/test_tree.py index 192702a94..8d29319fb 100644 --- a/test/test_tree.py +++ b/test/test_tree.py @@ -56,19 +56,7 @@ def test_invalid_tree_does_not_retain_partial_cache(object_format, invalid_posit list(tree) -@pytest.mark.parametrize("object_format", ["sha1", "sha256"]) -@pytest.mark.parametrize("scenario", ["executable", "symlink", "gitlink"]) -def test_tree_entry_modes_match_git(object_format, scenario): - with fixture_repo("tree-modes.sh", object_format, scenario) as repo: - root = read_only_fixture("tree-modes.sh", object_format, scenario) - oid = (root / "tree-id").read_text().strip() - metadata, name = (root / "entries").read_text().rstrip("\n").split("\t") - mode, kind, entry_oid = metadata.split() - assert mode in ("100755", "120000", "160000") - tree = Tree(repo, bytes.fromhex(oid), path="") - assert [(entry.mode, entry.type, entry.hexsha, entry.path) for entry in tree] == [ - (int(mode, 8), "submodule" if kind == "commit" else kind, entry_oid, name) - ] +def test_tree_modifier_orders_non_utf8_names_as_git_does(): with fixture_repo("tree-byte-order.sh") as repo: expected = (read_only_fixture("tree-byte-order.sh") / "order").read_bytes().split(b"\0")[:-1] tree = repo.head.commit.tree diff --git a/tests/fixtures/tree-modes.sh b/tests/fixtures/tree-modes.sh deleted file mode 100644 index fe1938a85..000000000 --- a/tests/fixtures/tree-modes.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env bash -set -eu -git init --initial-branch=main --object-format="$1" repo -cd repo -blob=$(printf 'content\n' | git hash-object -w --stdin) -subtree=$(printf '100644 blob %s\tinner\n' "$blob" | git mktree) -case "$2" in -executable) entry="100700 exe" oid=$blob ;; -symlink) entry="120777 link" oid=$blob ;; -gitlink) entry="140000 sub" oid=$subtree ;; -esac -# git mktree only writes canonical modes, so write the legacy mode literally. -escaped=$(printf %s "$oid" | sed 's/../\\x&/g') -{ printf '%s\0' "$entry"; printf %b "$escaped"; } | - git hash-object -w -t tree --literally --stdin >../tree-id -git ls-tree "$(cat ../tree-id)" >../entries From 2f5d70b8f9b656548def788493c1eb9ebadaeb6b Mon Sep 17 00:00:00 2001 From: Codex Date: Sun, 15 Nov 2026 13:11:53 +0100 Subject: [PATCH 3/3] ci: cancel superseded workflow runs Repeated updates currently leave older GitHub Actions runs executing even when their results are superseded. Add top-level `concurrency` to all ten workflows in `.github/workflows`, which perform validation and analysis rather than release publishing or deployment. Group runs by `${{ github.workflow }}-${{ github.ref }}` and enable `cancel-in-progress` so a newer run cancels older runs for the same workflow and ref while other workflows, branches, and pull requests remain independent. This also applies to scheduled and manually dispatched runs on the same ref. Validated all ten files with the existing `ruamel.yaml` installation, asserted the exact concurrency settings and unchanged remaining configuration, and ran `git diff --check`. GitHub Actions execution was not run locally. Agent-Model: unknown --- .github/workflows/alpine-test.yml | 4 ++++ .github/workflows/backend-benchmark.yml | 4 ++++ .github/workflows/codeql.yml | 4 ++++ .github/workflows/cygwin-test.yml | 4 ++++ .github/workflows/dependencies.yml | 4 ++++ .github/workflows/downstream.yml | 4 ++++ .github/workflows/git-cli.yml | 4 ++++ .github/workflows/lint.yml | 4 ++++ .github/workflows/pythonpackage.yml | 4 ++++ .github/workflows/zizmor.yml | 4 ++++ 10 files changed, 40 insertions(+) diff --git a/.github/workflows/alpine-test.yml b/.github/workflows/alpine-test.yml index 189826c0f..920f93066 100644 --- a/.github/workflows/alpine-test.yml +++ b/.github/workflows/alpine-test.yml @@ -1,5 +1,9 @@ name: test-alpine +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + on: push: branches: [main] diff --git a/.github/workflows/backend-benchmark.yml b/.github/workflows/backend-benchmark.yml index 140aa27cb..85503235a 100644 --- a/.github/workflows/backend-benchmark.yml +++ b/.github/workflows/backend-benchmark.yml @@ -1,5 +1,9 @@ name: Backend benchmark +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + on: push: branches: [main] diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 143c2de52..25c207db1 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -11,6 +11,10 @@ # name: "CodeQL" +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + on: push: branches: [main] diff --git a/.github/workflows/cygwin-test.yml b/.github/workflows/cygwin-test.yml index c55b73dd8..d5955958d 100644 --- a/.github/workflows/cygwin-test.yml +++ b/.github/workflows/cygwin-test.yml @@ -1,5 +1,9 @@ name: import-cygwin +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + on: push: branches: [main] diff --git a/.github/workflows/dependencies.yml b/.github/workflows/dependencies.yml index b58704fe9..e31a633b1 100644 --- a/.github/workflows/dependencies.yml +++ b/.github/workflows/dependencies.yml @@ -1,5 +1,9 @@ name: Dependency packages +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + on: push: branches: [main] diff --git a/.github/workflows/downstream.yml b/.github/workflows/downstream.yml index 85cf0062f..673122afe 100644 --- a/.github/workflows/downstream.yml +++ b/.github/workflows/downstream.yml @@ -1,5 +1,9 @@ name: Downstream compatibility +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + on: push: branches: [main] diff --git a/.github/workflows/git-cli.yml b/.github/workflows/git-cli.yml index b104fd4f4..bf12d1fa9 100644 --- a/.github/workflows/git-cli.yml +++ b/.github/workflows/git-cli.yml @@ -1,5 +1,9 @@ name: Minimum Git CLI +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + on: push: branches: [main] diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 496f4b093..ab2171ba3 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -1,5 +1,9 @@ name: Lint +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + on: push: branches: [main] diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index e8ef05cd4..842695409 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -3,6 +3,10 @@ name: Python package +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + on: push: branches: [main] diff --git a/.github/workflows/zizmor.yml b/.github/workflows/zizmor.yml index 201d28ab0..b38d834cb 100644 --- a/.github/workflows/zizmor.yml +++ b/.github/workflows/zizmor.yml @@ -1,5 +1,9 @@ name: zizmor +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + on: push: branches: [main]