Skip to content

Commit b465842

Browse files
codexByron
authored andcommitted
fix(gix): resolve push remote selectors with Git
With `push.default=upstream` and a mirror selected by `branch.main.pushRemote`, Git resolves `@{push}` through `mirror/main`. GixPython 0.4.0 resolves it through `origin/main`, so the Gix backend reported an object ID different from the one the push sent. Route push selectors through the managed Git fallback and record the open mismatch as GIX-45. The integration test verifies the receiver's object ID and the fallback on SHA-1 and SHA-256. The remote, revision, and CLI safety tests pass on both backends. Agent-Model: unknown
1 parent b06a835 commit b465842

4 files changed

Lines changed: 35 additions & 3 deletions

File tree

‎doc/gix-backend.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ and predate the current fallback; they do not establish native coverage.
383383
| Commit/tree serialization readback | Existing ODB stream; no separate `cat-file` process | The same storage and large-object fallbacks as ODB reads |
384384
| `Repo` opening/discovery | Native storage, worktree, object format and empty-tree metadata | Repository-format validation, unsupported layouts/environment and native validation gaps; GIX-1/14/19 |
385385
| 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 |
386-
| `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 |
386+
| `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, describe forms and push selectors; GIX-1/14/17/22/46 |
387387
| Revision path/mode metadata | Native revision specification, including tree paths and index stages | Custom/sparse indexes, unsupported revision grammar or path normalization |
388388
| `Remote.push` status | Managed revision lookup for explicit sources and exact reference lookup in the repository's default context | Git handles transport, abbreviated summary IDs, and exact reference checks with per-call environment overrides |
389389
| 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 |
@@ -1020,6 +1020,7 @@ identify the historical fixture where needed.
10201020
| 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. |
10211021
| 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. |
10221022
| 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. |
1023+
| GIX-46 | Bug (open) | On macOS with Git 2.54.0 and GixPython 0.4.0, `remote-cli.sh push-mirror` sets `main` to track `origin/main` with `branch.main.pushRemote=mirror`, `remote.mirror.mirror=true` and `push.default=upstream`. `git rev-parse --verify '@{push}'` resolves `mirror/main`, and `git push origin '@{push}:refs/heads/snapshot'` sends that commit. `Repository.rev_parse_single(b"@{push}")` returns `origin/main`. Both SHA-1 and SHA-256 reproduce the mismatch, including case-insensitive `@{PuSh}`. | Match Git's push remote and tracking-ref selection for mirror remotes. `_check_revision_grammar()` uses Git to resolve push selectors, including when `Remote.push()` captures a `PushInfo.local_hash`. `test_push_uses_mirror_remote_selector` checks the reported ID against the receiver and verifies CLI fallback on both object formats. |
10231024

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

‎git/_backend.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,12 @@ def _check_revision_grammar(ref: str) -> None:
171171
prefix, opener, remainder = ref.partition("@{")
172172
if opener and ":" not in prefix:
173173
selector, closer, _ = remainder.partition("}")
174+
if closer and selector.lower() == "push":
175+
raise _Unsupported("push remote selectors (GIX-46)")
174176
if closer and not (
175177
re.fullmatch(r"[0-9]+", selector)
176178
or (not prefix and re.fullmatch(r"-[0-9]+", selector))
177-
or selector.lower() in {"u", "upstream", "p", "push"}
179+
or selector.lower() in {"u", "upstream", "p"}
178180
):
179181
raise _Unsupported("textual reflog dates (GIX-39)")
180182

‎test/test_remote_cli.py‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import pytest
88

9-
from git import FetchInfo, Repo
9+
from git import FetchInfo, Repo, _backend
1010
from git.objects.submodule.util import sm_section
1111
from test.lib.fixtures import writable_fixture
1212

@@ -17,6 +17,24 @@ def remote_fixture(request):
1717
yield temporary.path().resolve()
1818

1919

20+
@pytest.mark.parametrize("remote_fixture", [("push-mirror", obj) for obj in ("sha1", "sha256")], indirect=True)
21+
def test_push_uses_mirror_remote_selector(remote_fixture):
22+
with Repo(remote_fixture / "source") as source, Repo(remote_fixture / "clone") as clone:
23+
expected = clone.commit("refs/remotes/mirror/main")
24+
assert expected != clone.commit("refs/remotes/origin/main")
25+
assert clone.git.rev_parse("--verify", "@{push}") == expected.hexsha
26+
fallback = ("rev_parse", "CLI: push remote selectors (GIX-46)")
27+
before = _backend.statistics().get(fallback, 0)
28+
29+
(info,) = clone.remote("origin").push("@{push}:refs/heads/snapshot")
30+
31+
assert source.heads.snapshot.commit == expected
32+
assert info.local_ref is None
33+
assert info.local_hash == expected.hexsha
34+
if _backend.name == "gix":
35+
assert _backend.statistics().get(fallback, 0) == before + 1
36+
37+
2038
@pytest.mark.parametrize(
2139
"remote_fixture",
2240
[("fetch", obj, refs) for obj in ("sha1", "sha256") for refs in ("files", "reftable")],

‎tests/fixtures/remote-cli.sh‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@ set -eu
44
git init --initial-branch=main --object-format="${2:-sha1}" --ref-format="${3:-files}" source
55
git -C source commit --allow-empty -m first
66
case "$1" in
7+
push-mirror)
8+
git clone --bare source mirror
9+
git -C source commit --allow-empty -m second
10+
git clone source clone
11+
git -C clone remote set-url origin ../source
12+
git -C clone remote add mirror ../mirror
13+
git -C clone fetch mirror
14+
git -C clone config branch.main.pushRemote mirror
15+
git -C clone config remote.mirror.mirror true
16+
git -C clone config push.default upstream
17+
;;
718
fetch)
819
git clone source clone
920
git -C clone remote set-url origin ../source

0 commit comments

Comments
 (0)