diff mercurial/context.py @ 38775:8c6775e812d8 stable

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."
author Yuya Nishihara <yuya@tcha.org>
date Sun, 19 Aug 2018 13:27:02 +0900
parents d558e53cd6b6
children d859b48730b8
line wrap: on
line diff
--- a/mercurial/context.py	Sat Aug 18 10:33:03 2018 +0900
+++ b/mercurial/context.py	Sun Aug 19 13:27:02 2018 +0900
@@ -1745,13 +1745,19 @@
         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)