Skip to content

Commit 60a2715

Browse files
authored
Merge pull request #2357 from JROtto5/fix/fetch-prune-line
fix(remote): skip pruned refs without a decode warning
2 parents 58428e3 + 06a40ba commit 60a2715

4 files changed

Lines changed: 44 additions & 27 deletions

File tree

‎doc/source/changes.rst‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,10 @@ API changes
175175
Missing paths within a valid tree revision raise ``Tree.join()``'s ``KeyError``
176176
with its missing-component message.
177177

178+
* ``FetchInfo.refresh()`` is deprecated and no longer needed. Git has used
179+
``t`` for fetch tag updates since 2.10, and GitPython requires Git 2.52 or
180+
newer. Remove calls to this method; ``git.refresh()`` still configures the
181+
Git executable.
178182
* ``IndexFile.entries`` returns an immutable snapshot keyed by ``(path, stage)``
179183
for compatibility with existing readers. Each access queries the current
180184
on-disk or pending index; previously returned snapshots retain their values.

‎git/__init__.py‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,8 @@ def refresh(path: Optional[PathLike] = None) -> None:
195195
:meth:`Git.refresh <git.cmd.Git.refresh>` for details on how to achieve this.
196196
197197
:note:
198-
This calls :meth:`Git.refresh <git.cmd.Git.refresh>` and sets other global
199-
configuration according to the effect of doing so. As such, this function should
200-
usually be used instead of using :meth:`Git.refresh <git.cmd.Git.refresh>` or
201-
:meth:`FetchInfo.refresh <git.remote.FetchInfo.refresh>` directly.
198+
This calls :meth:`Git.refresh <git.cmd.Git.refresh>` and updates ``GIT_OK``.
199+
Prefer this function to calling :meth:`Git.refresh <git.cmd.Git.refresh>` directly.
202200
203201
:note:
204202
This function is called automatically, with no arguments, at import time.
@@ -208,8 +206,6 @@ def refresh(path: Optional[PathLike] = None) -> None:
208206

209207
if not Git.refresh(path=path):
210208
return
211-
if not FetchInfo.refresh(): # noqa: F405
212-
return # type: ignore[unreachable]
213209

214210
GIT_OK = True
215211

‎git/remote.py‎

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,11 @@
99

1010
import logging
1111
import re
12-
13-
from git.cmd import Git, handle_process_output
14-
from git.compat import force_text
15-
from git.config import GitConfigParser, SectionConstraint, cp
16-
from git.refs import Reference, RemoteReference, SymbolicReference, TagReference
17-
from git.util import (
18-
CallableRemoteProgress,
19-
IterableList,
20-
IterableObj,
21-
LazyMixin,
22-
RemoteProgress,
23-
)
12+
import warnings
2413

2514
# typing-------------------------------------------------------
26-
2715
from typing import (
16+
TYPE_CHECKING,
2817
Any,
2918
Callable,
3019
Dict,
@@ -33,14 +22,24 @@
3322
NoReturn,
3423
Optional,
3524
Sequence,
36-
TYPE_CHECKING,
3725
TypeVar,
3826
Union,
3927
cast,
4028
overload,
4129
)
4230

31+
from git.cmd import Git, handle_process_output
32+
from git.compat import force_text
33+
from git.config import GitConfigParser, SectionConstraint, cp
34+
from git.refs import Reference, RemoteReference, SymbolicReference, TagReference
4335
from git.types import AnyGitObject, Literal, PathLike
36+
from git.util import (
37+
CallableRemoteProgress,
38+
IterableList,
39+
IterableObj,
40+
LazyMixin,
41+
RemoteProgress,
42+
)
4443

4544
if TYPE_CHECKING:
4645
from git.objects.commit import Commit
@@ -323,19 +322,17 @@ class FetchInfo(IterableObj):
323322
"*": 0,
324323
"=": HEAD_UPTODATE,
325324
" ": FAST_FORWARD,
326-
"-": TAG_UPDATE,
325+
"t": TAG_UPDATE,
327326
}
328327

329328
@classmethod
330329
def refresh(cls) -> Literal[True]:
331-
"""Update information about which :manpage:`git-fetch(1)` flags are supported
332-
by the git executable being used.
330+
"""Deprecated and no longer needed.
333331
334-
Called by the :func:`git.refresh` function in the top level ``__init__``.
332+
Git has used ``t`` for fetch tag updates since Git 2.10. GitPython
333+
requires Git 2.52 or newer, so no version-specific mapping is needed.
335334
"""
336-
cls._flag_map["t"] = cls.TAG_UPDATE
337-
cls._flag_map["-"] = 0
338-
335+
warnings.warn("FetchInfo.refresh() is deprecated and no longer needed", DeprecationWarning, stacklevel=2)
339336
return True
340337

341338
def __init__(
@@ -814,6 +811,9 @@ def _get_fetch_info_from_stderr(
814811
in_submodule = True
815812
if in_submodule:
816813
continue
814+
# --prune lists each ref it deleted; there is no ref left to report.
815+
if line[3:].startswith("[deleted]"):
816+
continue
817817
for cmd in cmds:
818818
if len(line) > 1 and line[0] == " " and line[1] == cmd:
819819
fetch_info_lines.append(line)

‎test/test_remote.py‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,23 @@ def test_base(self, rw_repo, remote_repo):
537537
"deleted everything but master",
538538
)
539539

540+
@with_rw_repo("HEAD", bare=False)
541+
def test_fetch_prune_skips_deleted_refs(self, rw_repo):
542+
remote = rw_repo.create_remote("self", rw_repo.git_dir)
543+
rw_repo.create_head("to_be_pruned")
544+
remote.fetch()
545+
self.assertIn("self/to_be_pruned", [ref.name for ref in remote.refs])
546+
547+
rw_repo.delete_head("to_be_pruned", force=True)
548+
with mock.patch("git.remote._logger.warning") as warning:
549+
fetch_info = remote.fetch(prune=True)
550+
self.assertNotIn("self/to_be_pruned", [info.name for info in fetch_info])
551+
self.assertNotIn("self/to_be_pruned", [ref.name for ref in remote.refs])
552+
self.assertFalse(
553+
[call for call in warning.call_args_list if "Cannot decode" in call.args[0]],
554+
"pruned refs are skipped without a warning",
555+
)
556+
540557
@with_rw_repo("HEAD", bare=True)
541558
def test_creation_and_removal(self, bare_rw_repo):
542559
new_name = "test_new_one"

0 commit comments

Comments
 (0)