Skip to content

Commit 1c9ef7d

Browse files
authored
Merge pull request #2364 from JROtto5/fix/push-non-ref-source
fix(remote): keep push results for sources that are not refs
2 parents ddc53fc + 2d6d27a commit 1c9ef7d

11 files changed

Lines changed: 371 additions & 46 deletions

File tree

‎doc/gix-backend.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,8 +383,9 @@ 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 |
388+
| `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 |
388389
| 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 |
389390
| Reference object reads | One exact native lookup for direct, symbolic and absent references | Partial names and native decoding errors |
390391
| Reference-name validation | Native full-name validation without opening a repository | Standalone names outside the native grammar; GIX-20 |
@@ -1025,6 +1026,7 @@ identify the historical fixture where needed.
10251026
| 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. |
10261027
| 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._superproject_branch()`, used by `branch`, `branch_name`, `branch_path` and `_branch_for_update()`, uses recursive `git symbolic-ref --quiet -- HEAD` through the CLI fallback. |
10271028
| 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. |
1029+
| 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. |
10281030

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

‎doc/source/changes.rst‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,15 @@ API changes
115115
current repository (``branch.<name>.remote=.``) as the upstream, instead of
116116
constructing an invalid ``refs/remotes/./...`` reference. Git resolves the
117117
upstream location; remote tracking branches retain their existing behavior.
118+
* ``repo.git(**options)`` returns a separate ``Git`` wrapper whose next subcommand
119+
receives the options. Chained calls such as ``repo.git(c="core.abbrev=12").log()``
120+
still work. A standalone ``repo.git(**options)`` call no longer affects later
121+
repository operations; use per-call environment overrides or
122+
``set_persistent_git_options()`` instead.
123+
* ``Remote.push()`` no longer drops results whose source is not a reference,
124+
such as a commit hash or ``HEAD~1``. Their ``PushInfo.local_ref`` is ``None``,
125+
and the new ``PushInfo.local_hash`` holds the hash reported by Git or
126+
resolved from an explicit source before the push, when available.
118127
* ``GitCmdObjectDB`` no longer inherits ``LooseObjectDB``. Its object reads,
119128
writes, existence checks, and enumeration use Git, including packed objects.
120129
Precompressed input streams and custom object-output writers are unsupported.

‎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

‎git/cmd.py‎

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@
1919
import sys
2020
import threading
2121
import time
22+
from copy import copy
2223
from subprocess import DEVNULL, PIPE, Popen
2324
from textwrap import dedent
25+
from types import MemberDescriptorType
2426

2527
# typing ---------------------------------------------------------------------------
2628
from typing import (
@@ -43,8 +45,8 @@
4345
overload,
4446
)
4547

46-
from git.compat import defenc, safe_decode, safe_encode
4748
from git import _backend
49+
from git.compat import defenc, safe_decode, safe_encode
4850
from git.exc import (
4951
CommandError,
5052
GitCommandError,
@@ -340,7 +342,13 @@ def dashify(string: str) -> str:
340342

341343

342344
def slots_to_dict(self: "Git", exclude: Sequence[str] = ()) -> Dict[str, Any]:
343-
return {s: getattr(self, s) for s in self.__slots__ if s not in exclude}
345+
state = {}
346+
for cls in reversed(type(self).__mro__):
347+
for name, descriptor in vars(cls).items():
348+
if isinstance(descriptor, MemberDescriptorType) and name not in exclude:
349+
with contextlib.suppress(AttributeError):
350+
state[name] = descriptor.__get__(self)
351+
return state
344352

345353

346354
def dict_to_slots_and__excluded_are_none(self: object, d: Mapping[str, Any], excluded: Sequence[str] = ()) -> None:
@@ -648,7 +656,7 @@ class Git:
648656
]
649657

650658
def __getstate__(self) -> Dict[str, Any]:
651-
return slots_to_dict(self, exclude=self._excluded_)
659+
return {**getattr(self, "__dict__", {}), **slots_to_dict(self, exclude=self._excluded_)}
652660

653661
def __setstate__(self, d: Dict[str, Any]) -> None:
654662
dict_to_slots_and__excluded_are_none(self, d, excluded=self._excluded_)
@@ -1820,7 +1828,10 @@ def _unpack_args(cls, arg_list: Sequence[Any]) -> List[str]:
18201828
return outlist
18211829

18221830
def __call__(self, **kwargs: Any) -> "Git":
1823-
"""Specify command line options to the git executable for a subcommand call.
1831+
"""Return a separate Git wrapper with options for its next subcommand call.
1832+
1833+
The original wrapper is unchanged. Discarding the returned wrapper discards
1834+
the one-shot options as well.
18241835
18251836
:param kwargs:
18261837
A dict of keyword arguments.
@@ -1831,8 +1842,13 @@ def __call__(self, **kwargs: Any) -> "Git":
18311842
18321843
git(work_tree='/tmp').difftool()
18331844
"""
1834-
self._git_options = self.transform_kwargs(split_single_char_options=True, **kwargs)
1835-
return self
1845+
# The copy excludes cached cat-file processes, which must not be shared.
1846+
command = copy(self)
1847+
command._repo = self._repo
1848+
command._environment = self._environment.copy()
1849+
command._repository_environment = self._repository_environment.copy()
1850+
command._git_options = self.transform_kwargs(split_single_char_options=True, **kwargs)
1851+
return command
18361852

18371853
@overload
18381854
def _call_process(

‎git/index/fun.py‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from git.cmd import Git
99
from git.exc import GitCommandError, HookExecutionError, UnsafeOptionError
1010
from git.types import PathLike
11+
1112
from .typ import BaseIndexEntry
1213

1314
if TYPE_CHECKING:
@@ -38,8 +39,7 @@ def run_commit_hook(name: str, index: "IndexFile", *args: str) -> None:
3839
raise UnsafeOptionError("Git arguments cannot contain NUL bytes")
3940
command = index.repo.git
4041
# Repo's automatic GIT_DIR bypasses Git's discovery-time ownership check.
41-
one_shot_options, command._git_options = command._git_options, ()
42-
options = [*command._persistent_git_options, *one_shot_options]
42+
options = list(command._persistent_git_options)
4343
discovery_env = {}
4444
if (
4545
"GIT_DIR" in command._repository_environment
@@ -57,7 +57,6 @@ def run_commit_hook(name: str, index: "IndexFile", *args: str) -> None:
5757
env=discovery_env,
5858
_repository_redirected="-C" in options,
5959
)
60-
command._git_options = one_shot_options
6160
try:
6261
index.repo.git._call_process_safe(
6362
"hook",

0 commit comments

Comments
 (0)