Patchwork [10,of,11,V5] update: add experimental config for default way of handling dirty wdir

login
register
mail settings
Submitter via Mercurial-devel
Date Feb. 28, 2017, 12:31 a.m.
Message ID <ae37f4578e3af6fd4cb7.1488241887@martinvonz.mtv.corp.google.com>
Download mbox | patch
Permalink /patch/18828/
State Accepted
Headers show

Comments

via Mercurial-devel - Feb. 28, 2017, 12:31 a.m.
# HG changeset patch
# User Martin von Zweigbergk <martinvonz@google.com>
# Date 1487030585 28800
#      Mon Feb 13 16:03:05 2017 -0800
# Node ID ae37f4578e3af6fd4cb7c29c9ab06ad0efd726da
# Parent  d23e5a40f9c4c8d3459255c6c2cb633452b914d8
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.

The default is read in hg.updatetotally(), which means it also applies
to "hg pull -u" and "hg unbundle -u".
Yuya Nishihara - March 6, 2017, 3 p.m.
On Mon, 27 Feb 2017 16:31:27 -0800, Martin von Zweigbergk via Mercurial-devel wrote:
> # HG changeset patch
> # User Martin von Zweigbergk <martinvonz@google.com>
> # Date 1487030585 28800
> #      Mon Feb 13 16:03:05 2017 -0800
> # Node ID ae37f4578e3af6fd4cb7c29c9ab06ad0efd726da
> # Parent  d23e5a40f9c4c8d3459255c6c2cb633452b914d8
> update: add experimental config for default way of handling dirty wdir

These look good to me. Queued, thanks.

Patch

diff -r d23e5a40f9c4 -r ae37f4578e3a mercurial/hg.py
--- a/mercurial/hg.py	Mon Feb 13 12:58:37 2017 -0800
+++ b/mercurial/hg.py	Mon Feb 13 16:03:05 2017 -0800
@@ -737,7 +737,10 @@ 
     This returns whether conflict is detected at updating or not.
     """
     if updatecheck is None:
-        updatecheck = 'linear'
+        updatecheck = ui.config('experimental', 'updatecheck')
+        if updatecheck not in ('abort', 'none', 'linear'):
+            # If not configured, or invalid value configured
+            updatecheck = 'linear'
     with repo.wlock():
         movemarkfrom = None
         warndest = False
diff -r d23e5a40f9c4 -r ae37f4578e3a tests/test-pull-update.t
--- a/tests/test-pull-update.t	Mon Feb 13 12:58:37 2017 -0800
+++ b/tests/test-pull-update.t	Mon Feb 13 16:03:05 2017 -0800
@@ -16,6 +16,21 @@ 
   $ echo 1.2 > foo
   $ hg ci -Am m
 
+Should respect config to disable dirty update
+  $ hg co -qC 0
+  $ echo 2 > foo
+  $ hg --config experimental.updatecheck=abort pull -u ../tt
+  pulling from ../tt
+  searching for changes
+  adding changesets
+  adding manifests
+  adding file changes
+  added 1 changesets with 1 changes to 1 files (+1 heads)
+  abort: uncommitted changes
+  [255]
+  $ hg --config extensions.strip= strip --no-backup tip
+  $ hg co -qC tip
+
 Should not update to the other topological branch:
 
   $ hg pull -u ../tt
diff -r d23e5a40f9c4 -r ae37f4578e3a 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,81 @@ 
   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 'none 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 --tool :merge3 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
+  ||||||| base
+  three
+  =======
+  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