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 ba887c2cb..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__( @@ -814,6 +811,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"