Skip to content
Merged
4 changes: 3 additions & 1 deletion doc/gix-backend.md
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,9 @@ and predate the current fallback; they do not establish native coverage.
| Commit/tree serialization readback | Existing ODB stream; no separate `cat-file` process | The same storage and large-object fallbacks as ODB reads |
| `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 |
| 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 |
| `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 |
| Revision path/mode metadata | Native revision specification, including tree paths and index stages | Custom/sparse indexes, unsupported revision grammar or path normalization |
| `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 |
| 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 |
Expand Down Expand Up @@ -1019,6 +1020,7 @@ identify the historical fixture where needed.
| 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. |
| 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. |
| 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. |
| 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. |

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
Expand Down
9 changes: 9 additions & 0 deletions doc/source/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,15 @@ API changes
current repository (``branch.<name>.remote=.``) as the upstream, instead of
constructing an invalid ``refs/remotes/./...`` reference. Git resolves the
upstream location; remote tracking branches retain their existing behavior.
* ``repo.git(**options)`` returns a separate ``Git`` wrapper whose next subcommand
receives the options. Chained calls such as ``repo.git(c="core.abbrev=12").log()``
still work. A standalone ``repo.git(**options)`` call no longer affects later
repository operations; use per-call environment overrides or
``set_persistent_git_options()`` instead.
* ``Remote.push()`` no longer drops results whose source is not a reference,
such as a commit hash or ``HEAD~1``. Their ``PushInfo.local_ref`` is ``None``,
and the new ``PushInfo.local_hash`` holds the hash reported by Git or
resolved from an explicit source before the push, when available.
* ``GitCmdObjectDB`` no longer inherits ``LooseObjectDB``. Its object reads,
writes, existence checks, and enumeration use Git, including packed objects.
Precompressed input streams and custom object-output writers are unsupported.
Expand Down
4 changes: 3 additions & 1 deletion git/_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,12 @@ def _check_revision_grammar(ref: str) -> None:
prefix, opener, remainder = ref.partition("@{")
if opener and ":" not in prefix:
selector, closer, _ = remainder.partition("}")
if closer and selector.lower() == "push":
raise _Unsupported("push remote selectors (GIX-46)")
if closer and not (
re.fullmatch(r"[0-9]+", selector)
or (not prefix and re.fullmatch(r"-[0-9]+", selector))
or selector.lower() in {"u", "upstream", "p", "push"}
or selector.lower() in {"u", "upstream", "p"}
):
raise _Unsupported("textual reflog dates (GIX-39)")

Expand Down
28 changes: 22 additions & 6 deletions git/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
import sys
import threading
import time
from copy import copy
from subprocess import DEVNULL, PIPE, Popen
from textwrap import dedent
from types import MemberDescriptorType

# typing ---------------------------------------------------------------------------
from typing import (
Expand All @@ -43,8 +45,8 @@
overload,
)

from git.compat import defenc, safe_decode, safe_encode
from git import _backend
from git.compat import defenc, safe_decode, safe_encode
from git.exc import (
CommandError,
GitCommandError,
Expand Down Expand Up @@ -340,7 +342,13 @@ def dashify(string: str) -> str:


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


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

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

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

def __call__(self, **kwargs: Any) -> "Git":
"""Specify command line options to the git executable for a subcommand call.
"""Return a separate Git wrapper with options for its next subcommand call.

The original wrapper is unchanged. Discarding the returned wrapper discards
the one-shot options as well.

:param kwargs:
A dict of keyword arguments.
Expand All @@ -1831,8 +1842,13 @@ def __call__(self, **kwargs: Any) -> "Git":

git(work_tree='/tmp').difftool()
"""
self._git_options = self.transform_kwargs(split_single_char_options=True, **kwargs)
return self
# The copy excludes cached cat-file processes, which must not be shared.
command = copy(self)
command._repo = self._repo
command._environment = self._environment.copy()
command._repository_environment = self._repository_environment.copy()
command._git_options = self.transform_kwargs(split_single_char_options=True, **kwargs)
return command

@overload
def _call_process(
Expand Down
5 changes: 2 additions & 3 deletions git/index/fun.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from git.cmd import Git
from git.exc import GitCommandError, HookExecutionError, UnsafeOptionError
from git.types import PathLike

from .typ import BaseIndexEntry

if TYPE_CHECKING:
Expand Down Expand Up @@ -38,8 +39,7 @@ def run_commit_hook(name: str, index: "IndexFile", *args: str) -> None:
raise UnsafeOptionError("Git arguments cannot contain NUL bytes")
command = index.repo.git
# Repo's automatic GIT_DIR bypasses Git's discovery-time ownership check.
one_shot_options, command._git_options = command._git_options, ()
options = [*command._persistent_git_options, *one_shot_options]
options = list(command._persistent_git_options)
discovery_env = {}
if (
"GIT_DIR" in command._repository_environment
Expand All @@ -57,7 +57,6 @@ def run_commit_hook(name: str, index: "IndexFile", *args: str) -> None:
env=discovery_env,
_repository_redirected="-C" in options,
)
command._git_options = one_shot_options
try:
index.repo.git._call_process_safe(
"hook",
Expand Down
Loading
Loading