commands.push: abort when revisions evaluate to empty set (BC)
authorGregory Szorc <gregory.szorc@gmail.com>
Mon, 23 Mar 2015 18:21:01 -0700
changeset 24429 69bd0ec2f9be
parent 24428 586d33f47dca
child 24430 98d9d33dfd95
commands.push: abort when revisions evaluate to empty set (BC) If the "-r" argument is specified to "hg push," the user has expressed an intent for a specific changeset to be present on the remote. If that expression cannot be mapped to a known changeset, the user's intent is ambiguous and cannot be acted upon without making assumptions. Previously, if arguments to `push -r <rev>` evaluated to an empty set (perhaps the user specified a revset that didn't evaluate to anything), the empty "revs" list would be passed down to "exchange.push" where it appears the empty list was being interpreted as "push everything." This patch adds validation to the "-r" argument to the push command. If the argument is specified but doesn't resolve to a changeset, the command will abort instead of doing something potentially unexpected. This patch is technically breaking backwards compatibility. I believe this is justified because the new behavior closes a crack that could result in undefined or under-defined behavior. Also, this patch doesn't drop client capabilities because if users really wanted to push all changesets, they can simply omit the "-r" argument from push completely.
mercurial/commands.py
tests/test-push-warn.t
--- a/mercurial/commands.py	Mon Mar 23 17:07:25 2015 -0700
+++ b/mercurial/commands.py	Mon Mar 23 18:21:01 2015 -0700
@@ -5152,6 +5152,9 @@
 
     if revs:
         revs = [repo.lookup(r) for r in scmutil.revrange(repo, revs)]
+        if not revs:
+            raise util.Abort(_("specified revisions evaluate to an empty set"),
+                             hint=_("use different revision arguments"))
 
     repo._subtoppath = dest
     try:
--- a/tests/test-push-warn.t	Mon Mar 23 17:07:25 2015 -0700
+++ b/tests/test-push-warn.t	Mon Mar 23 18:21:01 2015 -0700
@@ -19,6 +19,14 @@
   $ hg add t3
   $ hg commit -m "3"
 
+Specifying a revset that evaluates to null will abort
+
+  $ hg push -r '0 & 1' ../a
+  pushing to ../a
+  abort: specified revisions evaluate to an empty set
+  (use different revision arguments)
+  [255]
+
   $ hg push ../a
   pushing to ../a
   searching for changes