Skip to content

Commit eb37351

Browse files
codexByron
authored andcommitted
fix(remote): retain push status when revision validation rejects a source
Git accepts an option-shaped revision such as `-release~1` in a push refspec after `--`. The separate revision query rejects it, and the uncaught `UnsafeOptionError` previously stopped the stdout reader and lost later statuses. Treat the validation failure as an unavailable hash and retain the status. A mixed push regression checks that both results survive and that the receiver got the snapshot on both backends. Agent-Model: unknown
1 parent 32babf2 commit eb37351

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

‎git/remote.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
from git.cmd import Git, handle_process_output
3333
from git.compat import force_text
3434
from git.config import GitConfigParser, SectionConstraint, cp
35-
from git.exc import GitCommandError, ODBError
35+
from git.exc import GitCommandError, ODBError, UnsafeOptionError
3636
from git.refs import Reference, RemoteReference, SymbolicReference, TagReference
3737
from git.types import AnyGitObject, Literal, PathLike
3838
from git.util import (
@@ -289,7 +289,7 @@ def _from_line(cls, remote: "Remote", line: str) -> "PushInfo":
289289
local_hash = oids[0] if len(oids) == 1 else None
290290
else:
291291
local_hash = remote.repo.rev_parse(from_ref_string).hexsha
292-
except (ODBError, GitCommandError, ValueError):
292+
except (ODBError, GitCommandError, UnsafeOptionError, ValueError):
293293
pass
294294

295295
return PushInfo(flags, from_ref, to_ref_string, remote, old_commit, summary, local_hash)

‎test/test_remote.py‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,21 @@ def test_push_tree_path_source(self, rw_repo):
565565
self.assertEqual(info.local_hash, blob.hexsha)
566566
self.assertEqual(rw_repo.tags.snapshot.object.hexsha, blob.hexsha)
567567

568+
@with_rw_repo("HEAD", bare=False)
569+
def test_push_option_like_revision_source(self, rw_repo):
570+
remote = rw_repo.create_remote("self", rw_repo.git_dir)
571+
rw_repo.git.update_ref("refs/tags/-release", "HEAD")
572+
573+
result = remote.push(["-release~1:refs/heads/snapshot", "HEAD:refs/heads/ordinary"])
574+
575+
infos = {info.remote_ref_string: info for info in result}
576+
self.assertEqual(set(infos), {"refs/heads/snapshot", "refs/heads/ordinary"})
577+
self.assertTrue(infos["refs/heads/snapshot"].flags & PushInfo.NEW_HEAD)
578+
self.assertIsNone(infos["refs/heads/snapshot"].local_ref)
579+
self.assertIsNone(infos["refs/heads/snapshot"].local_hash)
580+
self.assertEqual(infos["refs/heads/ordinary"].local_ref, rw_repo.head)
581+
self.assertEqual(rw_repo.heads.snapshot.commit, rw_repo.head.commit.parents[0])
582+
568583
@with_rw_repo("HEAD", bare=False)
569584
def test_push_revision_sources(self, rw_repo):
570585
remote = rw_repo.create_remote("self", rw_repo.git_dir)

0 commit comments

Comments
 (0)