[PATCH] on clone failure, only remove directories we created

Steve Borho steve at borho.org
Tue Mar 31 21:34:31 CDT 2009


 mercurial/hg.py              |   6 +++++-
 tests/test-clone-failure     |  14 ++++++++++++++
 tests/test-clone-failure.out |   4 ++++
 3 files changed, 23 insertions(+), 1 deletions(-)


# HG changeset patch
# User Steve Borho <steve at borho.org>
# Date 1238552513 18000
# Node ID 76dddb1da6b97de4514df5d9d6cc5669193ac15c
# Parent  026bcd12a0adba249c2e1e1b43ccd4a8207c2e57
on clone failure, only remove directories we created

If the user created the clone target directory before running
the clone command, only cleanup the .hg/ repository when errors
occur.  Leave the empty target directory in place.

diff -r 026bcd12a0ad -r 76dddb1da6b9 mercurial/hg.py
--- a/mercurial/hg.py	Tue Mar 31 15:52:48 2009 -0400
+++ b/mercurial/hg.py	Tue Mar 31 21:21:53 2009 -0500
@@ -168,10 +168,14 @@
                 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 -r 026bcd12a0ad -r 76dddb1da6b9 tests/test-clone-failure
--- a/tests/test-clone-failure	Tue Mar 31 15:52:48 2009 -0400
+++ b/tests/test-clone-failure	Tue Mar 31 21:21:53 2009 -0500
@@ -49,4 +49,18 @@
 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 $?
+ls d
+echo repo should be gone
+ls d/.hg
+
 true
diff -r 026bcd12a0ad -r 76dddb1da6b9 tests/test-clone-failure.out
--- a/tests/test-clone-failure.out	Tue Mar 31 15:52:48 2009 -0400
+++ b/tests/test-clone-failure.out	Tue Mar 31 21:21:53 2009 -0500
@@ -12,3 +12,7 @@
 abort: destination 'q' is not empty
 abort: destination 'a' is not empty
 255
+adding c
+255
+repo should be gone
+ls: d/.hg: No such file or directory


More information about the Mercurial-devel mailing list