# HG changeset patch # User Gregory Szorc # Date 2015-03-24 01:21:01 # Node ID 69bd0ec2f9be865a95a1e3f2c335d313dab61d15 # Parent 586d33f47dca6e7dcf4667ddd94b55d3901b8ce2 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 ` 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. diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -5152,6 +5152,9 @@ def push(ui, repo, dest=None, **opts): 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: diff --git a/tests/test-push-warn.t b/tests/test-push-warn.t --- a/tests/test-push-warn.t +++ b/tests/test-push-warn.t @@ -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