Skip to content

Commit

Permalink
Exact command name matches are unambiguous
Browse files Browse the repository at this point in the history
When the user provides a StGit command name on the command line that
is a valid prefix for several commands, do not report that command as
ambiguous if it is an exact match for a command (or alias).

Fixes #110

Signed-off-by: Peter Grayson <pete@jpgrayson.net>
  • Loading branch information
jpgrayson committed Jun 14, 2021
1 parent d46a1fa commit 75688cd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
8 changes: 5 additions & 3 deletions stgit/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,17 @@ def canonical_cmd(self, key):
'Try "%s help" for a list of supported commands' % prog,
)
sys.exit(utils.STGIT_GENERAL_ERROR)
elif len(candidates) > 1:
elif len(candidates) == 1:
return candidates[0]
elif key in candidates:
return key
else:
out.error(
'Ambiguous command: %s' % key,
'Candidates are: %s' % ', '.join(candidates),
)
sys.exit(utils.STGIT_GENERAL_ERROR)

return candidates[0]

def __getitem__(self, key):
cmd_mod = self.get(key) or self.get(self.canonical_cmd(key))
if is_cmd_alias(cmd_mod):
Expand Down
8 changes: 8 additions & 0 deletions t/t0004-main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ test_expect_success 'Test help on ambiguous command' '
grep -e "Ambiguous command: pu"
'

test_expect_success 'Test ambiguous alias' '
test_config stgit.alias.show-stat "git show --stat" &&
stg show-stat &&
stg init &&
stg show &&
general_error stg sho 2>&1 | grep -e "Ambiguous command: sho"
'

test_expect_success 'Test version/--version equivalence' '
stg version > v0.txt &&
stg --version > v1.txt &&
Expand Down

0 comments on commit 75688cd

Please sign in to comment.