diff --git a/mercurial/hg.py b/mercurial/hg.py --- a/mercurial/hg.py +++ b/mercurial/hg.py @@ -168,10 +168,14 @@ def clone(ui, source, dest=None, pull=Fa copy = False if copy: + hgdir = os.path.realpath(os.path.join(dest, ".hg")) if not os.path.exists(dest): os.mkdir(dest) + else: + # only clean up directories we create ourselves + dir_cleanup.dir_ = hgdir try: - dest_path = os.path.realpath(os.path.join(dest, ".hg")) + dest_path = hgdir os.mkdir(dest_path) except OSError, inst: if inst.errno == errno.EEXIST: diff --git a/tests/test-clone-failure b/tests/test-clone-failure --- a/tests/test-clone-failure +++ b/tests/test-clone-failure @@ -49,4 +49,17 @@ echo stuff > a/a hg clone q a echo $? +# leave existing directory in place after clone failure +hg init c +cd c +echo c > c +hg commit -A -m test -d '0 0' +chmod -rx .hg/store/data +cd .. +mkdir d +hg clone c d 2> err +echo $? +test -d d && echo "dir is still here" || echo "dir is gone" +test -d d/.hg && echo "repo is still here" || echo "repo is gone" + true diff --git a/tests/test-clone-failure.out b/tests/test-clone-failure.out --- a/tests/test-clone-failure.out +++ b/tests/test-clone-failure.out @@ -12,3 +12,7 @@ destination directory: q abort: destination 'q' is not empty abort: destination 'a' is not empty 255 +adding c +255 +dir is still here +repo is gone