Patchwork [STABLE] merge: do not delete untracked files silently (issue5962)

login
register
mail settings
Submitter Yuya Nishihara
Date Aug. 19, 2018, 6:21 a.m.
Message ID <2b31e27533b32ea25f27.1534659698@mimosa>
Download mbox | patch
Permalink /patch/33886/
State Accepted
Headers show

Comments

Yuya Nishihara - Aug. 19, 2018, 6:21 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1534652822 -32400
#      Sun Aug 19 13:27:02 2018 +0900
# Branch stable
# Node ID 2b31e27533b32ea25f2758d7214e46dac8b0fb1d
# Parent  cee9043c7dba154af10cf2817190f8c1ed62de62
merge: do not delete untracked files silently (issue5962)

37450a122128, 2a774cae3a03, and 656ac240f392 weren't enough to prevent data
loss. No unknown "files" weren't deleted before 7a8a16f8ea22, "context: also
consider path conflicts when clearing unknown files."
via Mercurial-devel - Aug. 20, 2018, 4:08 p.m.
On Sat, Aug 18, 2018 at 11:22 PM Yuya Nishihara <yuya@tcha.org> wrote:

> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1534652822 -32400
> #      Sun Aug 19 13:27:02 2018 +0900
> # Branch stable
> # Node ID 2b31e27533b32ea25f2758d7214e46dac8b0fb1d
> # Parent  cee9043c7dba154af10cf2817190f8c1ed62de62
> merge: do not delete untracked files silently (issue5962)
>

Queued, thanks.

Patch

diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -1745,13 +1745,19 @@  class workingfilectx(committablefilectx)
         wvfs = self._repo.wvfs
         f = self._path
         wvfs.audit(f)
-        if wvfs.isdir(f) and not wvfs.islink(f):
-            wvfs.rmtree(f, forcibly=True)
         if self._repo.ui.configbool('experimental', 'merge.checkpathconflicts'):
+            # remove files under the directory as they should already be
+            # warned and backed up
+            if wvfs.isdir(f) and not wvfs.islink(f):
+                wvfs.rmtree(f, forcibly=True)
             for p in reversed(list(util.finddirs(f))):
                 if wvfs.isfileorlink(p):
                     wvfs.unlink(p)
                     break
+        else:
+            # don't remove files if path conflicts are not processed
+            if wvfs.isdir(f) and not wvfs.islink(f):
+                wvfs.removedirs(f)
 
     def setflags(self, l, x):
         self._repo.wvfs.setflags(self._path, l, x)
diff --git a/tests/test-merge1.t b/tests/test-merge1.t
--- a/tests/test-merge1.t
+++ b/tests/test-merge1.t
@@ -30,23 +30,24 @@  of the files in a commit we're updating 
 
   $ mkdir b && touch b/nonempty
   $ hg up
-  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  abort: Directory not empty: '$TESTTMP/t/b'
+  [255]
   $ hg ci
-  nothing changed
-  [1]
+  abort: last update was interrupted
+  (use 'hg update' to get a consistent checkout)
+  [255]
   $ hg sum
-  parent: 1:b8bb4a988f25 tip
-   commit #1
+  parent: 0:538afb845929 
+   commit #0
   branch: default
-  commit: (clean)
-  update: (current)
+  commit: 1 unknown (interrupted update)
+  update: 1 new changesets (update)
   phases: 2 draft
 
-The following line is commented out because the file doesn't exist at the moment, and some OSes error out even with `rm -f`.
-$ rm b/nonempty
+  $ rm b/nonempty
 
   $ hg up
-  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
   $ hg sum
   parent: 1:b8bb4a988f25 tip
    commit #1
diff --git a/tests/test-update-names.t b/tests/test-update-names.t
--- a/tests/test-update-names.t
+++ b/tests/test-update-names.t
@@ -50,7 +50,10 @@  make sure that this does not erase untra
   $ hg st
   ? name/file
   $ hg up 1
-  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  abort: Directory not empty: '$TESTTMP/r1/r2/name'
+  [255]
+  $ cat name/file
+  text
   $ cd ..
 
 #if symlink