changeset 31563:79d98e1b21a7

update: add flag to require update destination In some mercurial workflows, the default destination for update does not always work well and can lead to confusing behavior. With this flag enabled, every update command will require passing an explicit destination, eliminating this confusion.
author Ryan McElroy <rmcelroy@fb.com>
date Tue, 14 Mar 2017 17:43:18 -0700
parents 448acdee9161
children 13dc00c233b7
files mercurial/commands.py mercurial/help/config.txt tests/test-update-names.t
diffstat 3 files changed, 30 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/commands.py	Mon Mar 20 11:38:37 2017 +0900
+++ b/mercurial/commands.py	Tue Mar 14 17:43:18 2017 -0700
@@ -5349,6 +5349,11 @@
     if rev and node:
         raise error.Abort(_("please specify just one revision"))
 
+    if ui.configbool('commands', 'update.requiredest', False):
+        if not node and not rev and not date:
+            raise error.Abort(_('you must specify a destination'),
+                              hint=_('for example: hg update ".::"'))
+
     if rev is None or rev == '':
         rev = node
 
--- a/mercurial/help/config.txt	Mon Mar 20 11:38:37 2017 +0900
+++ b/mercurial/help/config.txt	Tue Mar 14 17:43:18 2017 -0700
@@ -414,6 +414,15 @@
     a different color mode than the pager (activated via the "pager"
     extension).
 
+``commands``
+----------
+
+``update.requiredest``
+    Require that the user pass a destination when running ``hg update``.
+    For example, ``hg update .::`` will be allowed, but a plain ``hg update``
+    will be disallowed.
+    (default: False)
+
 ``committemplate``
 ------------------
 
--- a/tests/test-update-names.t	Mon Mar 20 11:38:37 2017 +0900
+++ b/tests/test-update-names.t	Tue Mar 14 17:43:18 2017 -0700
@@ -88,3 +88,19 @@
   (consider changing to repo root: $TESTTMP/r1/r4)
 
 #endif
+
+  $ cd $TESTTMP
+  $ cat >> $HGRCPATH <<EOF
+  > [commands]
+  > update.requiredest = True
+  > EOF
+  $ hg init dest
+  $ cd dest
+  $ echo a >> a
+  $ hg commit -qAm aa
+  $ hg up
+  abort: you must specify a destination
+  (for example: hg update ".::")
+  [255]
+  $ hg up .
+  0 files updated, 0 files merged, 0 files removed, 0 files unresolved