[PATCH 6 of 6] update: add config for default way of handling dirty wdir

Martin von Zweigbergk martinvonz at google.com
Mon Feb 13 20:07:23 EST 2017


# HG changeset patch
# User Martin von Zweigbergk <martinvonz at google.com>
# Date 1487030585 28800
#      Mon Feb 13 16:03:05 2017 -0800
# Node ID 9df8dd6fd23bd52f4acaf87ea455749a97da4099
# Parent  75e5a492d7f69420a554fe498ae24060c755b09f
update: add config for default way of handling dirty wdir

This allows the user to set e.g. ui.updatecheck=abort to abort update
if the working directory is dirty, but still be able to override the
behavior with e.g. --merge when needed.

I considered adding a --mergelinear option to get back the old
behavior even when ui.updatecheck=abort is set, but I couldn't see why
anyone would prefer that over --merge.

diff -r 75e5a492d7f6 -r 9df8dd6fd23b mercurial/commands.py
--- a/mercurial/commands.py	Mon Feb 13 12:58:37 2017 -0800
+++ b/mercurial/commands.py	Mon Feb 13 16:03:05 2017 -0800
@@ -6544,7 +6544,14 @@
         raise error.Abort(_("can only specify one of -c/--check, -C/--clean, "
                             "and -m/merge"))
 
-    updatecheck = 'linear'
+    # Mapping of config value to internal value
+    updatecheckconfigs = {
+        "abort": "abort",
+        "merge": None,
+        "mergelinear": "linear"
+    }
+    configvalue = ui.config('ui', 'updatecheck')
+    updatecheck = updatecheckconfigs.get(configvalue, "linear")
     if check:
         updatecheck = 'abort'
     elif merge:
diff -r 75e5a492d7f6 -r 9df8dd6fd23b mercurial/help/config.txt
--- a/mercurial/help/config.txt	Mon Feb 13 12:58:37 2017 -0800
+++ b/mercurial/help/config.txt	Mon Feb 13 16:03:05 2017 -0800
@@ -1966,6 +1966,23 @@
     on all exceptions, even those recognized by Mercurial (such as
     IOError or MemoryError). (default: False)
 
+``updatecheck``
+    The default strategy for ``hg update`` to handle a dirty working copy. Can
+    be ``abort``, ``merge`` or ``mergelinear``.
+
+    ``abort``
+      Abort if the working copy is dirty.
+
+      ``merge``
+      Allow a dirty working copy and carry changes over to destination.
+
+      ``mergelinear``
+      Allow a dirty working copy and carry changes over to destination, but
+      fail if the destination is not an ancestor or descendant of the working
+      copy parent.
+
+    (default: ``mergelinear``)
+
 ``username``
     The committer of a changeset created when running "commit".
     Typically a person's name and email address, e.g. ``Fred Widget
diff -r 75e5a492d7f6 -r 9df8dd6fd23b tests/test-update-branches.t
--- a/tests/test-update-branches.t	Mon Feb 13 12:58:37 2017 -0800
+++ b/tests/test-update-branches.t	Mon Feb 13 16:03:05 2017 -0800
@@ -195,6 +195,58 @@
   parent=1
   M foo
 
+  $ echo '[ui]' >> .hg/hgrc
+  $ echo 'updatecheck = abort' >> .hg/hgrc
+
+  $ revtest 'none dirty linear' dirty 1 2
+  abort: uncommitted changes
+  parent=1
+  M foo
+
+  $ revtest 'none dirty linear' dirty 1 2 -c
+  abort: uncommitted changes
+  parent=1
+  M foo
+
+  $ revtest 'none dirty linear' dirty 1 2 -C
+  2 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  parent=2
+
+  $ echo 'updatecheck = merge' >> .hg/hgrc
+
+  $ revtest 'dirty cross'  dirty 3 4
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  parent=4
+  M foo
+
+  $ revtest 'none dirty linear' dirty 1 2
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  parent=2
+  M foo
+
+  $ revtest 'none dirty linear' dirty 1 2 -c
+  abort: uncommitted changes
+  parent=1
+  M foo
+
+  $ revtest 'none dirty linear' dirty 1 2 -C
+  2 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  parent=2
+
+  $ echo 'updatecheck = mergelinear' >> .hg/hgrc
+
+  $ revtest 'dirty cross'  dirty 3 4
+  abort: uncommitted changes
+  (commit or update --clean to discard changes)
+  parent=3
+  M foo
+
+Setup for later tests
+  $ revtest 'none dirty linear' dirty 1 2 -c
+  abort: uncommitted changes
+  parent=1
+  M foo
+
   $ cd ..
 
 Test updating to null revision


More information about the Mercurial-devel mailing list