Skip to content

Commit 6678a55

Browse files
codexByron
authored andcommitted
fix(remote): require an exact reference for a push source
A describe expression derived from a tag named `refs/releases/base` starts with `refs/`. `Reference.from_path()` accepts that prefix, so a successful push returned a reference that did not exist and discarded the pushed commit's ID. Use the shared exact-reference lookup before setting `local_ref`. A regression pushes the describe expression and verifies the destination and reported commit IDs on both backends. Agent-Model: unknown
1 parent 996a6eb commit 6678a55

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

‎git/remote.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,12 @@ def _from_line(cls, remote: "Remote", line: str) -> "PushInfo":
246246
is_revision = True
247247
else:
248248
try:
249-
from_ref = Reference.from_path(remote.repo, from_ref_string)
249+
candidate = Reference.from_path(remote.repo, from_ref_string)
250+
candidate._get_ref_info(remote.repo, from_ref_string)
250251
except ValueError:
251252
is_revision = True
253+
else:
254+
from_ref = candidate
252255

253256
# Commit handling, could be message or commit info
254257
old_commit: Optional[str] = None

‎test/test_remote.py‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,20 @@ def test_push_option_like_revision_source(self, rw_repo):
580580
self.assertEqual(infos["refs/heads/ordinary"].local_ref, rw_repo.head)
581581
self.assertEqual(rw_repo.heads.snapshot.commit, rw_repo.head.commit.parents[0])
582582

583+
@with_rw_repo("HEAD", bare=False)
584+
def test_push_describe_source_with_ref_prefix(self, rw_repo):
585+
remote = rw_repo.create_remote("self", rw_repo.git_dir)
586+
current = rw_repo.head.commit
587+
rw_repo.create_tag("refs/releases/base", current.parents[0])
588+
source = rw_repo.git.describe("--tags", "--long", "--match=refs/releases/base")
589+
self.assertTrue(source.startswith("refs/releases/base-"))
590+
591+
(info,) = remote.push(f"{source}:refs/heads/snapshot")
592+
593+
self.assertIsNone(info.local_ref)
594+
self.assertEqual(info.local_hash, current.hexsha)
595+
self.assertEqual(rw_repo.heads.snapshot.commit, current)
596+
583597
@with_rw_repo("HEAD", bare=False)
584598
def test_push_revision_sources(self, rw_repo):
585599
remote = rw_repo.create_remote("self", rw_repo.git_dir)

0 commit comments

Comments
 (0)