context: also consider path conflicts when clearing unknown files
When clearing unknown files to remove path conflicts, also delete files that
conflict with the target file's path.
Differential Revision: https://phab.mercurial-scm.org/D785
--- a/mercurial/context.py Mon Oct 02 14:05:30 2017 -0700
+++ b/mercurial/context.py Mon Oct 02 14:05:30 2017 -0700
@@ -1933,8 +1933,13 @@
``write()`` can be called successfully.
"""
wvfs = self._repo.wvfs
- if wvfs.isdir(self._path) and not wvfs.islink(self._path):
- wvfs.removedirs(self._path)
+ f = self._path
+ 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
def setflags(self, l, x):
self._repo.wvfs.setflags(self._path, l, x)
--- a/tests/test-pathconflicts-basic.t Mon Oct 02 14:05:30 2017 -0700
+++ b/tests/test-pathconflicts-basic.t Mon Oct 02 14:05:30 2017 -0700
@@ -35,6 +35,7 @@
[1]
$ hg update --clean .
1 files updated, 0 files merged, 1 files removed, 0 files unresolved
+ $ rm a~853701544ac3
Basic update - local directory conflicts with remote file
@@ -46,13 +47,19 @@
abort: untracked files in working directory differ from files in requested revision
[255]
$ hg up --clean file
- abort: *: '$TESTTMP/repo/a' (glob)
- [255]
+ 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+ (activating bookmark file)
+
+Repo state is ok
-Repo is in a very bad state now - recover manually
-
- $ rm -r a
- $ hg up -q --clean 0
+ $ hg sum
+ parent: 1:853701544ac3
+ file
+ branch: default
+ bookmarks: *file
+ commit: (clean)
+ update: 2 new changesets (update)
+ phases: 4 draft
Basic update - untracked file conflicts with remote directory
@@ -62,6 +69,9 @@
a: replacing untracked file
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
(activating bookmark dir)
+ $ cat a.orig
+ untracked
+ $ rm -f a.orig
Basic clean update - local directory conflicts with changed remote file
@@ -73,11 +83,17 @@
abort: *: '$TESTTMP/repo/a' (glob)
[255]
$ hg up --clean file2
- abort: *: '$TESTTMP/repo/a' (glob)
- [255]
+ 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+ (activating bookmark file2)
+
+Repo state is ok
-Repo is in a very bad state now - recover manually
+ $ hg sum
+ parent: 2:f64e09fac717
+ file2
+ branch: default
+ bookmarks: *file2
+ commit: (clean)
+ update: 1 new changesets, 2 branch heads (merge)
+ phases: 4 draft
- $ rm -r a
- $ hg up -q --clean 0
-