changeset 4137:26596a6b6518

Create the parent directory when checking out symlinks.
author Giorgos Keramidas <keramida@ceid.upatras.gr>
date Fri, 23 Feb 2007 17:54:34 +0200
parents eb5d4fec1487
children 85237110c371
files mercurial/localrepo.py tests/test-symlinks tests/test-symlinks.out
diffstat 3 files changed, 27 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -525,11 +525,15 @@ class localrepository(repo.repository):
     def wwrite(self, filename, data, flags):
         data = self._filter("decode", filename, data)
         if "l" in flags:
+            f = self.wjoin(filename)
             try:
-                os.unlink(self.wjoin(filename))
+                os.unlink(f)
             except OSError:
                 pass
-            os.symlink(data, self.wjoin(filename))
+            d = os.path.dirname(f)
+            if not os.path.exists(d):
+                os.makedirs(d)
+            os.symlink(data, f)
         else:
             try:
                 if self._link(filename):
--- a/tests/test-symlinks
+++ b/tests/test-symlinks
@@ -55,3 +55,18 @@ echo '# try symlink outside repo to file
 ln -s x/f ../z
 # this should fail
 hg status ../z && { echo hg mistakenly exited with status 0; exit 1; } || :
+
+cd .. ; rm -r test
+hg init test; cd test;
+
+echo '# try cloning symlink in a subdir'
+echo '1. commit a symlink'
+mkdir -p a/b/c
+cd a/b/c
+ln -s /path/to/symlink/source demo
+cd ../../..
+hg stat
+hg commit -A -m 'add symlink in a/b/c subdir'
+echo '2. clone it'
+cd ..
+hg clone test testclone
--- a/tests/test-symlinks.out
+++ b/tests/test-symlinks.out
@@ -14,3 +14,9 @@ a.c: unsupported file type (type is fifo
 A f
 # try symlink outside repo to file inside
 abort: ../z not under root
+# try cloning symlink in a subdir
+1. commit a symlink
+? a/b/c/demo
+adding a/b/c/demo
+2. clone it
+1 files updated, 0 files merged, 0 files removed, 0 files unresolved