diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -5942,6 +5942,15 @@ def push(ui, repo, dest=None, **opts): if not revs: raise error.Abort(_("specified revisions evaluate to an empty set"), hint=_("use different revision arguments")) + elif path.pushrev: + # It doesn't make any sense to specify ancestor revisions. So limit + # to DAG heads to make discovery simpler. + expr = revset.formatspec('heads(%r)', path.pushrev) + revs = scmutil.revrange(repo, [expr]) + revs = [repo[rev].node() for rev in revs] + if not revs: + raise error.Abort(_('default push revset for path evaluates to an ' + 'empty set')) repo._subtoppath = dest try: diff --git a/mercurial/help/config.txt b/mercurial/help/config.txt --- a/mercurial/help/config.txt +++ b/mercurial/help/config.txt @@ -1282,6 +1282,18 @@ The following sub-options can be defined The URL to use for push operations. If not defined, the location defined by the path's main entry is used. +``pushrev`` + A revset defining which revisions to push by default. + + When :hg:`push` is executed without a ``-r`` argument, the revset + defined by this sub-option is evaluated to determine what to push. + + For example, a value of ``.`` will push the working directory's + revision by default. + + Revsets specifying bookmarks will not result in the bookmark being + pushed. + The following special named paths exist: ``default`` diff --git a/mercurial/ui.py b/mercurial/ui.py --- a/mercurial/ui.py +++ b/mercurial/ui.py @@ -1281,6 +1281,10 @@ def pushurlpathoption(ui, path, value): return str(u) +@pathsuboption('pushrev', 'pushrev') +def pushrevpathoption(ui, path, value): + return value + class path(object): """Represents an individual path and its configuration.""" diff --git a/tests/test-default-push.t b/tests/test-default-push.t --- a/tests/test-default-push.t +++ b/tests/test-default-push.t @@ -105,4 +105,43 @@ Windows needs a leading slash to make a adding file changes added 1 changesets with 1 changes to 1 files +:pushrev is used when no -r is passed + + $ cat >> .hg/hgrc << EOF + > default:pushrev = . + > EOF + $ hg -q up -r 0 + $ echo head1 > foo + $ hg -q commit -A -m head1 + $ hg -q up -r 0 + $ echo head2 > foo + $ hg -q commit -A -m head2 + $ hg push -f + pushing to file:/*/$TESTTMP/pushurlsource/../pushurldest (glob) + searching for changes + adding changesets + adding manifests + adding file changes + added 1 changesets with 1 changes to 1 files (+1 heads) + + $ hg --config 'paths.default:pushrev=draft()' push -f + pushing to file:/*/$TESTTMP/pushurlsource/../pushurldest (glob) + searching for changes + adding changesets + adding manifests + adding file changes + added 1 changesets with 1 changes to 1 files (+1 heads) + +Invalid :pushrev raises appropriately + + $ hg --config 'paths.default:pushrev=notdefined()' push + pushing to file:/*/$TESTTMP/pushurlsource/../pushurldest (glob) + hg: parse error: unknown identifier: notdefined + [255] + + $ hg --config 'paths.default:pushrev=(' push + pushing to file:/*/$TESTTMP/pushurlsource/../pushurldest (glob) + hg: parse error at 1: not a prefix: end + [255] + $ cd .. diff --git a/tests/test-help.t b/tests/test-help.t --- a/tests/test-help.t +++ b/tests/test-help.t @@ -1515,6 +1515,18 @@ Test section lookup The URL to use for push operations. If not defined, the location defined by the path's main entry is used. + "pushrev" + A revset defining which revisions to push by default. + + When 'hg push' is executed without a "-r" argument, the revset defined + by this sub-option is evaluated to determine what to push. + + For example, a value of "." will push the working directory's revision + by default. + + Revsets specifying bookmarks will not result in the bookmark being + pushed. + The following special named paths exist: "default"