Patchwork [2,of,2] clone: abort if default destination has no meaningful name (BC)

login
register
mail settings
Submitter Yuya Nishihara
Date March 21, 2014, 4:53 p.m.
Message ID <8253e55930a3e85ed540.1395420825@gimlet>
Download mbox | patch
Permalink /patch/4017/
State Accepted
Commit 8253e55930a3e85ed54075d09fa17f059d1737f4
Headers show

Comments

Yuya Nishihara - March 21, 2014, 4:53 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1395416772 -32400
#      Sat Mar 22 00:46:12 2014 +0900
# Node ID 8253e55930a3e85ed54075d09fa17f059d1737f4
# Parent  069bf1b821c8015596f2926090cb274e4a0ee727
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.
Sean Farley - March 21, 2014, 7:22 p.m.
Yuya Nishihara <yuya@tcha.org> writes:

> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1395416772 -32400
> #      Sat Mar 22 00:46:12 2014 +0900
> # Node ID 8253e55930a3e85ed54075d09fa17f059d1737f4
> # Parent  069bf1b821c8015596f2926090cb274e4a0ee727
> 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.

Nice :-) I run into this issue all the time because I map smf:// to my
home server (the issue is that 'hg clone smf://project' clones into the
current directory).
Augie Fackler - April 12, 2014, 4:20 p.m.
On Fri, Mar 21, 2014 at 02:22:38PM -0500, Sean Farley wrote:
>
> Yuya Nishihara <yuya@tcha.org> writes:
>
> > # HG changeset patch
> > # User Yuya Nishihara <yuya@tcha.org>
> > # Date 1395416772 -32400
> > #      Sat Mar 22 00:46:12 2014 +0900
> > # Node ID 8253e55930a3e85ed54075d09fa17f059d1737f4
> > # Parent  069bf1b821c8015596f2926090cb274e4a0ee727
> > 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.
>
> Nice :-) I run into this issue all the time because I map smf:// to my
> home server (the issue is that 'hg clone smf://project' clones into the
> current directory).

Agreed. It was queued at some point, which is good.

(mentioning this mostly for the patchbot)

> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel

Patch

diff --git a/mercurial/hg.py b/mercurial/hg.py
--- a/mercurial/hg.py
+++ b/mercurial/hg.py
@@ -132,13 +132,16 @@  def defaultdest(source):
     >>> 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 @@  def clone(ui, peeropts, source, dest=Non
 
     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)
 
diff --git a/tests/test-http-clone-r.t b/tests/test-http-clone-r.t
--- a/tests/test-http-clone-r.t
+++ b/tests/test-http-clone-r.t
@@ -197,4 +197,11 @@  clone remote via stream
   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