Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions doc/source/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 2 additions & 6 deletions git/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,8 @@ def refresh(path: Optional[PathLike] = None) -> None:
:meth:`Git.refresh <git.cmd.Git.refresh>` for details on how to achieve this.

:note:
This calls :meth:`Git.refresh <git.cmd.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 <git.cmd.Git.refresh>` or
:meth:`FetchInfo.refresh <git.remote.FetchInfo.refresh>` directly.
This calls :meth:`Git.refresh <git.cmd.Git.refresh>` and updates ``GIT_OK``.
Prefer this function to calling :meth:`Git.refresh <git.cmd.Git.refresh>` directly.

:note:
This function is called automatically, with no arguments, at import time.
Expand All @@ -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

Expand Down
42 changes: 21 additions & 21 deletions git/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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__(
Expand Down Expand Up @@ -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)
Expand Down
17 changes: 17 additions & 0 deletions test/test_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading