changeset 7927:a218ba5f60df

allow clone into existing but empty directories
author Steve Borho <steve@borho.org>
date Sun, 29 Mar 2009 16:15:06 -0500
parents edf2d83a11aa
children 0796c8862bee
files mercurial/hg.py tests/test-clone tests/test-clone-failure tests/test-clone-failure.out tests/test-clone.out
diffstat 5 files changed, 25 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/hg.py	Sun Mar 29 19:56:53 2009 -0300
+++ b/mercurial/hg.py	Sun Mar 29 16:15:06 2009 -0500
@@ -131,7 +131,10 @@
     source = localpath(source)
 
     if os.path.exists(dest):
-        raise util.Abort(_("destination '%s' already exists") % dest)
+        if not os.path.isdir(dest):
+            raise util.Abort(_("destination '%s' already exists") % dest)
+        elif os.listdir(dest):
+            raise util.Abort(_("destination '%s' is not empty") % dest)
 
     class DirCleanup(object):
         def __init__(self, dir_):
--- a/tests/test-clone	Sun Mar 29 19:56:53 2009 -0300
+++ b/tests/test-clone	Sun Mar 29 16:15:06 2009 -0500
@@ -60,4 +60,11 @@
 hg clone --pull a g
 hg -R g verify
 
+echo
+echo % clone to '.'
+mkdir h
+cd h
+hg clone ../a .
+cd ..
+
 exit 0
--- a/tests/test-clone-failure	Sun Mar 29 19:56:53 2009 -0300
+++ b/tests/test-clone-failure	Sun Mar 29 16:15:06 2009 -0500
@@ -43,4 +43,10 @@
 cd ..
 hg clone q
 
+# destination directory not empty
+mkdir a 
+echo stuff > a/a
+hg clone q a
+echo $?
+
 true
--- a/tests/test-clone-failure.out	Sun Mar 29 19:56:53 2009 -0300
+++ b/tests/test-clone-failure.out	Sun Mar 29 16:15:06 2009 -0500
@@ -4,9 +4,11 @@
 255
 abort: repository a not found!
 255
-abort: destination '../a' already exists
+abort: Permission denied: ../a
 255
 abort: repository a not found!
 255
 destination directory: q
-abort: destination 'q' already exists
+abort: destination 'q' is not empty
+abort: destination 'a' is not empty
+255
--- a/tests/test-clone.out	Sun Mar 29 19:56:53 2009 -0300
+++ b/tests/test-clone.out	Sun Mar 29 16:15:06 2009 -0500
@@ -50,3 +50,7 @@
 crosschecking files in changesets and manifests
 checking files
 2 files, 11 changesets, 11 total revisions
+
+% clone to .
+updating working directory
+2 files updated, 0 files merged, 0 files removed, 0 files unresolved