From 1be793c0bea8ef9c4b9fa2398da537aacb835e30 Mon Sep 17 00:00:00 2001 From: JROtto5 <222316562+JROtto5@users.noreply.github.com> Date: Mon, 23 Nov 2026 00:04:57 -0500 Subject: [PATCH 1/2] fix(remote): skip pruned refs without a decode warning `git fetch --prune` reports each remote-tracking ref it deletes as - [deleted] (none) -> origin/gone `_get_fetch_info_from_stderr()` collects these with the other fetch lines, `FetchInfo._from_line()` can't resolve a ref that no longer exists, and every pruned ref logs "Cannot decode fetch result" at WARNING. The result list was already right; only the warning was spurious. Skip the deleted lines before decoding, as the test already expects ("These should just be skipped"). `test_fetch_prune_skips_deleted_refs` prunes a branch fetched from the repository itself and checks that no decode warning is logged; it needs no network and fails without this change under both the `cli` and `gix` backends. Agent-Model: claude-opus-5-5 --- git/remote.py | 3 +++ test/test_remote.py | 17 +++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/git/remote.py b/git/remote.py index ba887c2cb..7051488e6 100644 --- a/git/remote.py +++ b/git/remote.py @@ -814,6 +814,9 @@ def _get_fetch_info_from_stderr( in_submodule = True if in_submodule: continue + # --prune lists each ref it deleted; there is no ref left to report. + if line[3:].startswith("[deleted]"): + continue for cmd in cmds: if len(line) > 1 and line[0] == " " and line[1] == cmd: fetch_info_lines.append(line) diff --git a/test/test_remote.py b/test/test_remote.py index d3ecbb33a..ba18dce3a 100644 --- a/test/test_remote.py +++ b/test/test_remote.py @@ -537,6 +537,23 @@ def test_base(self, rw_repo, remote_repo): "deleted everything but master", ) + @with_rw_repo("HEAD", bare=False) + def test_fetch_prune_skips_deleted_refs(self, rw_repo): + remote = rw_repo.create_remote("self", rw_repo.git_dir) + rw_repo.create_head("to_be_pruned") + remote.fetch() + self.assertIn("self/to_be_pruned", [ref.name for ref in remote.refs]) + + rw_repo.delete_head("to_be_pruned", force=True) + with mock.patch("git.remote._logger.warning") as warning: + fetch_info = remote.fetch(prune=True) + self.assertNotIn("self/to_be_pruned", [info.name for info in fetch_info]) + self.assertNotIn("self/to_be_pruned", [ref.name for ref in remote.refs]) + self.assertFalse( + [call for call in warning.call_args_list if "Cannot decode" in call.args[0]], + "pruned refs are skipped without a warning", + ) + @with_rw_repo("HEAD", bare=True) def test_creation_and_removal(self, bare_rw_repo): new_name = "test_new_one" From 06a40ba2e2db26a15cc2386cea336b3c51d51e8c Mon Sep 17 00:00:00 2001 From: Byron Date: Tue, 24 Nov 2026 08:20:07 +0100 Subject: [PATCH 2/2] review --- doc/source/changes.rst | 4 ++++ git/__init__.py | 8 ++------ git/remote.py | 39 ++++++++++++++++++--------------------- 3 files changed, 24 insertions(+), 27 deletions(-) diff --git a/doc/source/changes.rst b/doc/source/changes.rst index f9e8a13b2..e768a3544 100644 --- a/doc/source/changes.rst +++ b/doc/source/changes.rst @@ -170,6 +170,10 @@ API changes Missing paths within a valid tree revision raise ``Tree.join()``'s ``KeyError`` with its missing-component message. +* ``FetchInfo.refresh()`` is deprecated and no longer needed. Git has used + ``t`` for fetch tag updates since 2.10, and GitPython requires Git 2.52 or + newer. Remove calls to this method; ``git.refresh()`` still configures the + Git executable. * ``IndexFile.entries`` returns an immutable snapshot keyed by ``(path, stage)`` for compatibility with existing readers. Each access queries the current on-disk or pending index; previously returned snapshots retain their values. diff --git a/git/__init__.py b/git/__init__.py index b8a38d1fd..74dc634ae 100644 --- a/git/__init__.py +++ b/git/__init__.py @@ -195,10 +195,8 @@ def refresh(path: Optional[PathLike] = None) -> None: :meth:`Git.refresh ` for details on how to achieve this. :note: - This calls :meth:`Git.refresh ` and sets other global - configuration according to the effect of doing so. As such, this function should - usually be used instead of using :meth:`Git.refresh ` or - :meth:`FetchInfo.refresh ` directly. + This calls :meth:`Git.refresh ` and updates ``GIT_OK``. + Prefer this function to calling :meth:`Git.refresh ` directly. :note: This function is called automatically, with no arguments, at import time. @@ -208,8 +206,6 @@ def refresh(path: Optional[PathLike] = None) -> None: if not Git.refresh(path=path): return - if not FetchInfo.refresh(): # noqa: F405 - return # type: ignore[unreachable] GIT_OK = True diff --git a/git/remote.py b/git/remote.py index 7051488e6..d5ab4914e 100644 --- a/git/remote.py +++ b/git/remote.py @@ -9,22 +9,11 @@ import logging import re - -from git.cmd import Git, handle_process_output -from git.compat import force_text -from git.config import GitConfigParser, SectionConstraint, cp -from git.refs import Reference, RemoteReference, SymbolicReference, TagReference -from git.util import ( - CallableRemoteProgress, - IterableList, - IterableObj, - LazyMixin, - RemoteProgress, -) +import warnings # typing------------------------------------------------------- - from typing import ( + TYPE_CHECKING, Any, Callable, Dict, @@ -33,14 +22,24 @@ NoReturn, Optional, Sequence, - TYPE_CHECKING, TypeVar, Union, cast, overload, ) +from git.cmd import Git, handle_process_output +from git.compat import force_text +from git.config import GitConfigParser, SectionConstraint, cp +from git.refs import Reference, RemoteReference, SymbolicReference, TagReference from git.types import AnyGitObject, Literal, PathLike +from git.util import ( + CallableRemoteProgress, + IterableList, + IterableObj, + LazyMixin, + RemoteProgress, +) if TYPE_CHECKING: from git.objects.commit import Commit @@ -323,19 +322,17 @@ class FetchInfo(IterableObj): "*": 0, "=": HEAD_UPTODATE, " ": FAST_FORWARD, - "-": TAG_UPDATE, + "t": TAG_UPDATE, } @classmethod def refresh(cls) -> Literal[True]: - """Update information about which :manpage:`git-fetch(1)` flags are supported - by the git executable being used. + """Deprecated and no longer needed. - Called by the :func:`git.refresh` function in the top level ``__init__``. + Git has used ``t`` for fetch tag updates since Git 2.10. GitPython + requires Git 2.52 or newer, so no version-specific mapping is needed. """ - cls._flag_map["t"] = cls.TAG_UPDATE - cls._flag_map["-"] = 0 - + warnings.warn("FetchInfo.refresh() is deprecated and no longer needed", DeprecationWarning, stacklevel=2) return True def __init__(