diff --git a/doc/hgrc.5.txt b/doc/hgrc.5.txt --- a/doc/hgrc.5.txt +++ b/doc/hgrc.5.txt @@ -377,6 +377,9 @@ ui:: remote command to use for clone/push/pull operations. Default is 'hg'. ssh;; command to use for SSH connections. Default is 'ssh'. + strict;; + Require exact command names, instead of allowing unambiguous + abbreviations. True or False. Default is False. timeout;; The timeout used when a lock is held (in seconds), a negative value means no timeout. Default is 600. diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -507,7 +507,7 @@ def help_(ui, name=None, with_version=Fa if with_version: show_version(ui) ui.write('\n') - aliases, i = findcmd(name) + aliases, i = findcmd(ui, name) # synopsis ui.write("%s\n\n" % i[2]) @@ -1154,7 +1154,7 @@ def debugcomplete(ui, cmd='', **opts): options = [] otables = [globalopts] if cmd: - aliases, entry = findcmd(cmd) + aliases, entry = findcmd(ui, cmd) otables.append(entry[1]) for t in otables: for o in t: @@ -1164,7 +1164,7 @@ def debugcomplete(ui, cmd='', **opts): ui.write("%s\n" % "\n".join(options)) return - clist = findpossible(cmd).keys() + clist = findpossible(ui, cmd).keys() clist.sort() ui.write("%s\n" % "\n".join(clist)) @@ -3149,7 +3149,7 @@ norepo = ("clone init version help debug " debugindex debugindexdot") optionalrepo = ("paths serve debugconfig") -def findpossible(cmd): +def findpossible(ui, cmd): """ Return cmd -> (aliases, command table entry) for each matching command. @@ -3162,7 +3162,7 @@ def findpossible(cmd): found = None if cmd in aliases: found = cmd - else: + elif not ui.config("ui", "strict"): for a in aliases: if a.startswith(cmd): found = a @@ -3178,9 +3178,9 @@ def findpossible(cmd): return choice -def findcmd(cmd): +def findcmd(ui, cmd): """Return (aliases, command table entry) for command string.""" - choice = findpossible(cmd) + choice = findpossible(ui, cmd) if choice.has_key(cmd): return choice[cmd] @@ -3215,7 +3215,7 @@ def parse(ui, args): if args: cmd, args = args[0], args[1:] - aliases, i = findcmd(cmd) + aliases, i = findcmd(ui, cmd) cmd = aliases[0] defaults = ui.config("defaults", cmd) if defaults: diff --git a/tests/test-strict b/tests/test-strict new file mode 100755 --- /dev/null +++ b/tests/test-strict @@ -0,0 +1,19 @@ +#!/bin/sh + +hg init + +echo a > a +hg ci -d '0 0' -Ama + +hg an a + +HGRCPATH=$HGTMP/.hgrc; export HGRCPATH +echo "[ui]" >> $HGTMP/.hgrc +echo "strict=True" >> $HGTMP/.hgrc + +hg an a +hg annotate a + +echo % should succeed - up is an alias, not an abbreviation + +hg up diff --git a/tests/test-strict.out b/tests/test-strict.out new file mode 100644 --- /dev/null +++ b/tests/test-strict.out @@ -0,0 +1,26 @@ +adding a +0: a +hg: unknown command 'an' +Mercurial Distributed SCM + +basic commands (use "hg help" for the full list or option "-v" for details): + + add add the specified files on the next commit + annotate show changeset information per file line + clone make a copy of an existing repository + commit commit the specified files or all outstanding changes + diff diff repository (or selected files) + export dump the header and diffs for one or more changesets + init create a new repository in the given directory + log show revision history of entire repository or files + parents show the parents of the working dir or revision + pull pull changes from the specified source + push push changes to the specified destination + remove remove the specified files on the next commit + revert revert files or dirs to their states as of some revision + serve export the repository via HTTP + status show changed files in the working directory + update update or merge working directory +0: a +% should succeed - up is an alias, not an abbreviation +0 files updated, 0 files merged, 0 files removed, 0 files unresolved