changeset 5329:7e6138cb8d38

copy: if destination ends with "/", make sure it's a directory Fixes issue724.
author Alexis S. L. Carvalho <alexis@cecm.usp.br>
date Mon, 24 Sep 2007 19:00:11 -0300
parents c6682cdada2f
children 4528858e7202
files mercurial/commands.py tests/test-rename tests/test-rename.out
diffstat 3 files changed, 14 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/commands.py	Sun Sep 23 14:40:44 2007 +0200
+++ b/mercurial/commands.py	Mon Sep 24 19:00:11 2007 -0300
@@ -623,9 +623,12 @@
         raise util.Abort(_('no destination specified'))
     dest = pats.pop()
     destdirexists = os.path.isdir(dest)
-    if (len(pats) > 1 or util.patkind(pats[0], None)[0]) and not destdirexists:
-        raise util.Abort(_('with multiple sources, destination must be an '
-                         'existing directory'))
+    if not destdirexists:
+        if len(pats) > 1 or util.patkind(pats[0], None)[0]:
+            raise util.Abort(_('with multiple sources, destination must be an '
+                               'existing directory'))
+        if dest.endswith(os.sep) or os.altsep and dest.endswith(os.altsep):
+            raise util.Abort(_('destination %s is not a directory') % dest)
     if opts['after']:
         tfn = targetpathafterfn
     else:
--- a/tests/test-rename	Sun Sep 23 14:40:44 2007 +0200
+++ b/tests/test-rename	Mon Sep 24 19:00:11 2007 -0300
@@ -88,6 +88,11 @@
 diff d1/b d2/b
 hg update -C
 
+echo "# attempt to move one file into a non-existent directory"
+hg rename d1/a dx/
+hg status -C
+hg update -C
+
 echo "# attempt to move potentially more than one file into a non-existent"
 echo "# directory"
 hg rename 'glob:d1/**' dx
--- a/tests/test-rename.out	Sun Sep 23 14:40:44 2007 +0200
+++ b/tests/test-rename.out	Mon Sep 24 19:00:11 2007 -0300
@@ -166,6 +166,9 @@
 ---
 > d2/b
 3 files updated, 0 files merged, 3 files removed, 0 files unresolved
+# attempt to move one file into a non-existent directory
+abort: destination dx/ is not a directory
+0 files updated, 0 files merged, 0 files removed, 0 files unresolved
 # attempt to move potentially more than one file into a non-existent
 # directory
 abort: with multiple sources, destination must be an existing directory