# HG changeset patch # User Giorgos Keramidas # Date 1172246074 -7200 # Node ID 26596a6b6518547ea13592a62fc0ad33af6ebb8f # Parent eb5d4fec148723f00c655d43055341f1597a9c5c 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 @@ -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): diff --git a/tests/test-symlinks b/tests/test-symlinks --- 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 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.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