[PATCH 2 of 2] Create the parent directory when checking out symlinks

Giorgos Keramidas keramida at ceid.upatras.gr
Fri Feb 23 15:55:38 UTC 2007


# HG changeset patch
# User Giorgos Keramidas <keramida at ceid.upatras.gr>
# Date 1172246074 -7200
# Node ID 61107f2b5e73c6e013c0fd0830366f7d0d0ce011
# Parent  8450de1af661b51bf9c732276a180cc01f47bfdc
Create the parent directory when checking out symlinks.

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -512,11 +512,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):
diff --git a/tests/test-symlinks b/tests/test-symlinks
--- a/tests/test-symlinks
+++ b/tests/test-symlinks
@@ -55,3 +55,18 @@ ln -s x/f ../z
 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
diff --git a/tests/test-symlinks.out b/tests/test-symlinks.out
--- a/tests/test-symlinks.out
+++ b/tests/test-symlinks.out
@@ -14,3 +14,9 @@ A f
 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



More information about the Mercurial-devel mailing list