clone: abort if default destination has no meaningful name (BC)
authorYuya Nishihara <yuya@tcha.org>
Sat, 22 Mar 2014 00:46:12 +0900
changeset 20800 8253e55930a3
parent 20799 069bf1b821c8
child 20801 9c5183cb9bca
clone: abort if default destination has no meaningful name (BC) If source URL has no path, default destination is resolved as '.'. It is surprising than useful, and perhaps an unexpected behavior. This change does not solve issue3880, but can avoid to clone into current directory by accident.
mercurial/hg.py
tests/test-http-clone-r.t
--- a/mercurial/hg.py	Sat Mar 22 00:46:08 2014 +0900
+++ b/mercurial/hg.py	Sat Mar 22 00:46:12 2014 +0900
@@ -132,13 +132,16 @@
     >>> defaultdest('/')
     ''
     >>> defaultdest('')
-    '.'
+    ''
     >>> defaultdest('http://example.org/')
-    '.'
+    ''
     >>> defaultdest('http://example.org/foo/')
     'foo'
     '''
-    return os.path.basename(os.path.normpath(util.url(source).path or ''))
+    path = util.url(source).path
+    if not path:
+        return ''
+    return os.path.basename(os.path.normpath(path))
 
 def share(ui, source, dest=None, update=True):
     '''create a shared repository'''
@@ -290,7 +293,8 @@
 
     if dest is None:
         dest = defaultdest(source)
-        ui.status(_("destination directory: %s\n") % dest)
+        if dest:
+            ui.status(_("destination directory: %s\n") % dest)
     else:
         dest = ui.expandpath(dest)
 
--- a/tests/test-http-clone-r.t	Sat Mar 22 00:46:08 2014 +0900
+++ b/tests/test-http-clone-r.t	Sat Mar 22 00:46:12 2014 +0900
@@ -197,4 +197,11 @@
   checking files
   4 files, 9 changesets, 7 total revisions
   $ cd ..
+
+no default destination if url has no path:
+
+  $ hg clone http://localhost:$HGPORT/
+  abort: empty destination path is not valid
+  [255]
+
   $ cat error.log