Skip to content

Commit 7386a15

Browse files
committed
fix(remote): keep the note on fetch results
`FetchInfo.note` was always empty. Git appends the note to a fetch status line after two spaces, e.g. `-> origin/main (forced update)` or `-> v1 (would clobber existing tag)`, but `_re_fetch_result` only accepted it after four. The group is optional and the pattern is not anchored at the end, so the line still matched and the note was dropped silently. Accept the two spaces Git writes. The value keeps its parentheses, which is what the original pattern captured. `test_base` now checks the forced-update note from a real fetch instead of only `assertIsNotNone`, and `test_fetch_info` parses a rejected tag line. Both fail without this change. The changelog notes the now populated field. Agent-Model: claude-opus-5-5
1 parent fe74a6f commit 7386a15

3 files changed

Lines changed: 12 additions & 2 deletions

File tree

‎doc/source/changes.rst‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,8 @@ API changes
232232
collection. Close files and repositories you opened yourself before removing a
233233
repository on Windows; call ``gc.collect()`` only if your own objects are
234234
reachable solely through reference cycles.
235+
* ``FetchInfo.note`` carries Git's note for the reference, such as
236+
``(forced update)`` or ``(would clobber existing tag)``. It was always empty.
235237

236238
3.2.1
237239
=====

‎git/remote.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ class FetchInfo(IterableObj):
315315
ERROR,
316316
) = [1 << x for x in range(8)]
317317

318-
_re_fetch_result = re.compile(r"^ *(?:.{0,3})(.) (\[[\w \.$@]+\]|[\w\.$@]+) +(.+) -> ([^ ]+)( \(.*\)?$)?")
318+
_re_fetch_result = re.compile(r"^ *(?:.{0,3})(.) (\[[\w \.$@]+\]|[\w\.$@]+) +(.+) -> ([^ ]+)( \(.*\)?$)?")
319319

320320
_flag_map: Dict[flagKeyLiteral, int] = {
321321
"!": ERROR,

‎test/test_remote.py‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ def get_info(res, remote, name):
229229
mkey = "%s/%s" % (remote, "master")
230230
master_info = res[mkey]
231231
self.assertTrue(master_info.flags & FetchInfo.FORCED_UPDATE)
232-
self.assertIsNotNone(master_info.note)
232+
self.assertEqual(master_info.note, "(forced update)")
233233

234234
# Normal fast forward - set head back to previous one.
235235
rhead.commit = remote_commit
@@ -573,6 +573,14 @@ def test_fetch_info(self):
573573
self.assertIsInstance(info.ref, ref_type)
574574
self.assertEqual(info.remote_ref_path, source)
575575
self.assertTrue(info.flags & FetchInfo.NEW_HEAD)
576+
self.assertEqual(info.note, "")
577+
info = FetchInfo._from_line(
578+
self.rorepo,
579+
"! [rejected] tag -> subdir/tag (would clobber existing tag)",
580+
["refs/tags/tag:refs/tags/subdir/tag"],
581+
)
582+
self.assertTrue(info.flags & FetchInfo.REJECTED)
583+
self.assertEqual(info.note, "(would clobber existing tag)")
576584
with self.assertRaises(ValueError):
577585
FetchInfo._from_line(self.rorepo, "= [up to date] master -> ambiguous")
578586

0 commit comments

Comments
 (0)