changeset 43163:5617b748aad8

push: support config option to require revs be specified when running push Differential Revision: https://phab.mercurial-scm.org/D6989
author Kyle Lippincott <spectral@google.com>
date Sat, 05 Oct 2019 13:39:35 -0700
parents 3c6976b1f693
children c32531444cdc
files mercurial/commands.py mercurial/configitems.py mercurial/help/config.txt tests/test-push.t
diffstat 4 files changed, 66 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/commands.py	Thu Oct 10 11:33:33 2019 +0200
+++ b/mercurial/commands.py	Sat Oct 05 13:39:35 2019 -0700
@@ -5615,6 +5615,9 @@
             raise error.Abort(
                 _(b'default push revset for path evaluates to an empty set')
             )
+    elif ui.configbool(b'commands', b'push.require-revs'):
+        raise error.Abort(_(b'no revisions specified to push'),
+                          hint=_(b'did you mean "hg push -r ."?'))
 
     repo._subtoppath = dest
     try:
--- a/mercurial/configitems.py	Thu Oct 10 11:33:33 2019 +0200
+++ b/mercurial/configitems.py	Sat Oct 05 13:39:35 2019 -0700
@@ -228,6 +228,9 @@
     b'commands', b'grep.all-files', default=False, experimental=True,
 )
 coreconfigitem(
+    b'commands', b'push.require-revs', default=False,
+)
+coreconfigitem(
     b'commands', b'resolve.confirm', default=False,
 )
 coreconfigitem(
--- a/mercurial/help/config.txt	Thu Oct 10 11:33:33 2019 +0200
+++ b/mercurial/help/config.txt	Sat Oct 05 13:39:35 2019 -0700
@@ -442,6 +442,14 @@
     Show status of files in the working directory after successful commit.
     (default: False)
 
+``push.require-revs``
+    Require revisions to push be specified using one or more mechanisms such as
+    specifying them positionally on the command line, using ``-r``, ``-b``,
+    and/or ``-B`` on the command line, or using ``paths.<path>:pushrev`` in the
+    configuration. If this is enabled and revisions are not specified, the
+    command aborts.
+    (default: False)
+
 ``resolve.confirm``
     Confirm before performing action if no filename is passed.
     (default: False)
--- a/tests/test-push.t	Thu Oct 10 11:33:33 2019 +0200
+++ b/tests/test-push.t	Sat Oct 05 13:39:35 2019 -0700
@@ -348,3 +348,55 @@
   [255]
 
   $ [ ! -f owned ] || echo 'you got owned'
+
+Test `commands.push.require-revs`
+---------------------------------
+
+  $ hg clone -q test-revflag test-require-revs-source
+  $ hg init test-require-revs-dest
+  $ cd test-require-revs-source
+  $ cat >> .hg/hgrc << EOF
+  > [paths]
+  > default = ../test-require-revs-dest
+  > [commands]
+  > push.require-revs=1
+  > EOF
+  $ hg push
+  pushing to $TESTTMP/test-require-revs-dest
+  abort: no revisions specified to push
+  (did you mean "hg push -r ."?)
+  [255]
+  $ hg push -r 0
+  pushing to $TESTTMP/test-require-revs-dest
+  searching for changes
+  adding changesets
+  adding manifests
+  adding file changes
+  added 1 changesets with 1 changes to 1 files
+  $ hg bookmark -r 0 push-this-bookmark
+(test that -B (bookmark) works for specifying "revs")
+  $ hg push -B push-this-bookmark
+  pushing to $TESTTMP/test-require-revs-dest
+  searching for changes
+  no changes found
+  exporting bookmark push-this-bookmark
+  [1]
+(test that -b (branch)  works for specifying "revs")
+  $ hg push -b default
+  pushing to $TESTTMP/test-require-revs-dest
+  searching for changes
+  abort: push creates new remote head [0-9a-f]+! (re)
+  (merge or see 'hg help push' for details about pushing new heads)
+  [255]
+(demonstrate that even though we don't have anything to exchange, we're still
+showing the error)
+  $ hg push
+  pushing to $TESTTMP/test-require-revs-dest
+  abort: no revisions specified to push
+  (did you mean "hg push -r ."?)
+  [255]
+  $ hg push --config paths.default:pushrev=0
+  pushing to $TESTTMP/test-require-revs-dest
+  searching for changes
+  no changes found
+  [1]