Patchwork [15,of,15,V5] pathcomplete: remove ambiguous entries for sole completion on a directory

login
register
mail settings
Submitter Sean Farley
Date Nov. 26, 2013, 7:54 p.m.
Message ID <f9d326693c8880f88f0f.1385499294@laptop.local>
Download mbox | patch
Permalink /patch/3169/
State Accepted
Commit 1df77035c8141d4586ff5af84c34d54cb9912402
Headers show

Comments

Sean Farley - Nov. 26, 2013, 7:54 p.m.
# HG changeset patch
# User Sean Farley <sean.michael.farley@gmail.com>
# Date 1385399562 18000
#      Mon Nov 25 12:12:42 2013 -0500
# Node ID f9d326693c8880f88f0fea1478db6bd88e75c3b4
# Parent  7908c45ed714ef93803c7fdd7cf408be84d1d3f7
pathcomplete: remove ambiguous entries for sole completion on a directory

Previously, directories were added with the trailing slash and, if there was
only one completion, then another ambiguous entry was created using '.', as
follows:

$ hg rm mer<TAB>
mercurial/./  mercurial//

This was added in fa6d5c62f3bd (though, some logic existed before that) to work
around bash completion adding a space after the sole entry because we treated
directories and files the same. We no longer do that now so we remove this
unneeded code.

Tests have been updated to match this new behavior.

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -2243,11 +2243,11 @@ 
                 if fullpaths:
                     addfile(f)
                     continue
                 s = f.find(os.sep, speclen)
                 if s >= 0:
-                    adddir(f[:s + 1])
+                    adddir(f[:s])
                 else:
                     addfile(f)
         return files, dirs
 
     acceptable = ''
@@ -2264,14 +2264,10 @@ 
     files, dirs = set(), set()
     for spec in specs:
         f, d = complete(spec, acceptable or 'nmar')
         files.update(f)
         dirs.update(d)
-    if not files and len(dirs) == 1:
-        # force the shell to consider a completion that matches one
-        # directory and zero files to be ambiguous
-        dirs.add(iter(dirs).next() + '.')
     files.update(dirs)
     ui.write('\n'.join(repo.pathto(p, cwd) for p in sorted(files)))
     ui.write('\n')
 
 @command('debugpushkey', [], _('REPO NAMESPACE [KEY OLD NEW]'))
diff --git a/tests/test-completion.t b/tests/test-completion.t
--- a/tests/test-completion.t
+++ b/tests/test-completion.t
@@ -303,11 +303,11 @@ 
 
 Test debugpathcomplete
 
   $ hg debugpathcomplete f
   fee
-  fie/
+  fie
   fo
   $ hg debugpathcomplete -f f
   fee
   fie/dead
   fie/live
@@ -315,16 +315,10 @@ 
 
   $ hg rm Fum
   $ hg debugpathcomplete -r F
   Fum
 
-If one directory and no files match, give an ambiguous answer
-
-  $ hg debugpathcomplete fi
-  fie/
-  fie/.
-
 Test debuglabelcomplete
 
   $ hg debuglabelcomplete
   Fum
   default