diff --git a/mercurial/hg.py b/mercurial/hg.py --- a/mercurial/hg.py +++ b/mercurial/hg.py @@ -131,7 +131,10 @@ def clone(ui, source, dest=None, pull=Fa 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_): diff --git a/tests/test-clone b/tests/test-clone --- a/tests/test-clone +++ b/tests/test-clone @@ -60,4 +60,11 @@ echo % use --pull hg clone --pull a g hg -R g verify +echo +echo % clone to '.' +mkdir h +cd h +hg clone ../a . +cd .. + exit 0 diff --git a/tests/test-clone-failure b/tests/test-clone-failure --- a/tests/test-clone-failure +++ b/tests/test-clone-failure @@ -43,4 +43,10 @@ hg init cd .. hg clone q +# destination directory not empty +mkdir a +echo stuff > a/a +hg clone q a +echo $? + 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 @@ -4,9 +4,11 @@ abort: error: Connection refused 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 diff --git a/tests/test-clone.out b/tests/test-clone.out --- a/tests/test-clone.out +++ b/tests/test-clone.out @@ -50,3 +50,7 @@ checking manifests 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