Skip to content

Commit 1be793c

Browse files
committed
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
1 parent 029964a commit 1be793c

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

‎git/remote.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,9 @@ def _get_fetch_info_from_stderr(
814814
in_submodule = True
815815
if in_submodule:
816816
continue
817+
# --prune lists each ref it deleted; there is no ref left to report.
818+
if line[3:].startswith("[deleted]"):
819+
continue
817820
for cmd in cmds:
818821
if len(line) > 1 and line[0] == " " and line[1] == cmd:
819822
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)