Patchwork [6,of,6,V2] update: add experimental config for default way of handling dirty wdir

login
register
mail settings
Submitter via Mercurial-devel
Date Feb. 14, 2017, 11:08 p.m.
Message ID <391a00a73428cf672379.1487113721@martinvonz.mtv.corp.google.com>
Download mbox | patch
Permalink /patch/18501/
State Accepted
Headers show

Comments

via Mercurial-devel - Feb. 14, 2017, 11:08 p.m.
# HG changeset patch
# User Martin von Zweigbergk <martinvonz@google.com>
# Date 1487030585 28800
#      Mon Feb 13 16:03:05 2017 -0800
# Node ID 391a00a73428cf6723792408ff753d3bc6c2d401
# Parent  231ca552e7ff7eabc70326d2bf57994f3673e04e
update: add experimental config for default way of handling dirty wdir

This allows the user to set e.g. experimental.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 experimental.updatecheck=abort is set, but I
couldn't see why anyone would prefer that over --merge.

Patch

diff -r 231ca552e7ff -r 391a00a73428 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
@@ -5987,7 +5987,10 @@ 
         raise error.Abort(_("can only specify one of -C/--clean, -c/--check, "
                             "or -m/merge"))
 
-    updatecheck = 'linear'
+    updatecheck = ui.config('experimental', 'updatecheck')
+    if updatecheck not in ('abort', 'none', 'linear'):
+        # If not configured, or invalid value configured
+        updatecheck = 'linear'
     if check:
         updatecheck = 'abort'
     elif merge:
diff -r 231ca552e7ff -r 391a00a73428 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,79 @@ 
   parent=1
   M foo
 
+  $ echo '[experimental]' >> .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 = none' >> .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
+
+  $ hg co -qC 3
+  $ echo dirty >> a
+  $ hg co 4
+  merging a
+  warning: conflicts while merging a! (edit, then use 'hg resolve --mark')
+  0 files updated, 0 files merged, 0 files removed, 1 files unresolved
+  use 'hg resolve' to retry unresolved file merges
+  [1]
+  $ hg st
+  M a
+  ? a.orig
+  $ cat a
+  <<<<<<< working copy: 6efa171f091b - test: 3
+  three
+  dirty
+  =======
+  four
+  >>>>>>> destination:  d047485b3896 b1 - test: 4
+  $ rm a.orig
+
+Uses default value of "linear" when value is misspelled
+  $ echo 'updatecheck = linyar' >> .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