Skip to content

Commit 32babf2

Browse files
codexByron
authored andcommitted
fix(remote): split push status refspecs at the final colon
Git prints the complete source expression in porcelain output. A tree-path expression such as `HEAD:file.txt` includes a colon of its own. Splitting on every colon made GitPython discard the status even though Git had created the destination tag. Split only at the final colon so revision lookup receives the full source expression. Test the result and the tag's object ID on the CLI and Gix backends. Agent-Model: unknown
1 parent 1321d14 commit 32babf2

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

‎git/remote.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ def _from_line(cls, remote: "Remote", line: str) -> "PushInfo":
236236
# END handle control character
237237

238238
# from_to handling
239-
from_ref_string, to_ref_string = from_to.split(":")
239+
from_ref_string, to_ref_string = from_to.rsplit(":", 1)
240240
from_ref: Union[SymbolicReference, None] = None
241241
is_revision = False
242242
if not flags & cls.DELETED and from_ref_string != "(delete)":

‎test/test_remote.py‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,17 @@ def test_fetch_prune_skips_deleted_refs(self, rw_repo):
554554
"pruned refs are skipped without a warning",
555555
)
556556

557+
@with_rw_repo("HEAD", bare=False)
558+
def test_push_tree_path_source(self, rw_repo):
559+
remote = rw_repo.create_remote("self", rw_repo.git_dir)
560+
blob = next(rw_repo.head.commit.tree.traverse(predicate=lambda item, depth: item.type == "blob"))
561+
562+
(info,) = remote.push(f"HEAD:{blob.path}:refs/tags/snapshot")
563+
564+
self.assertIsNone(info.local_ref)
565+
self.assertEqual(info.local_hash, blob.hexsha)
566+
self.assertEqual(rw_repo.tags.snapshot.object.hexsha, blob.hexsha)
567+
557568
@with_rw_repo("HEAD", bare=False)
558569
def test_push_revision_sources(self, rw_repo):
559570
remote = rw_repo.create_remote("self", rw_repo.git_dir)

0 commit comments

Comments
 (0)