update: fix bug when update tries to modify folder symlink stable
authorKostia Balytskyi <ikostia@fb.com>
Thu, 21 Jul 2016 15:55:47 -0700
branchstable
changeset 29629 b33c0c38d68f
parent 29628 6217180f9ab8
child 29630 67b180c0e263
update: fix bug when update tries to modify folder symlink In 1e4512eac59e0114bc60ecbcdc4157fc0fa0439d, I introduced a new bug: when a symlink points to a folder in commit A and to another folder in commit B, while updating from A to B, Mercurial will try to use removedir on this symlink, which will fail. This is a very bad bug, since it basically renders symlinks to folders unusable in repos. Added test case fails without a fix and passes with it.
mercurial/merge.py
tests/test-update-names.t
--- a/mercurial/merge.py	Mon Jul 25 12:59:52 2016 +0800
+++ b/mercurial/merge.py	Thu Jul 21 15:55:47 2016 -0700
@@ -1082,7 +1082,7 @@
                     if e.errno != errno.ENOENT:
                         raise
 
-            if repo.wvfs.isdir(f):
+            if repo.wvfs.isdir(f) and not repo.wvfs.islink(f):
                 repo.wvfs.removedirs(f)
             wwrite(f, fctx(f).data(), flags, backgroundclose=True)
             if i == 100:
--- a/tests/test-update-names.t	Mon Jul 25 12:59:52 2016 +0800
+++ b/tests/test-update-names.t	Thu Jul 21 15:55:47 2016 -0700
@@ -53,3 +53,22 @@
   abort: *: '$TESTTMP/r1/r2/name' (glob)
   [255]
   $ cd ..
+
+#if symlink
+
+Test update when two commits have symlinks that point to different folders
+  $ hg init r3 && cd r3
+  $ echo root > root && hg ci -Am root
+  adding root
+  $ mkdir folder1 && mkdir folder2
+  $ ln -s folder1 folder
+  $ hg ci -Am "symlink to folder1"
+  adding folder
+  $ rm folder
+  $ ln -s folder2 folder
+  $ hg ci -Am "symlink to folder2"
+  $ hg up 1
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ cd ..
+
+#endif