Skip to content

Commit 75688cd

Browse files
committed
Exact command name matches are unambiguous
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 <[email protected]>
1 parent d46a1fa commit 75688cd

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

stgit/main.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,17 @@ def canonical_cmd(self, key):
6969
'Try "%s help" for a list of supported commands' % prog,
7070
)
7171
sys.exit(utils.STGIT_GENERAL_ERROR)
72-
elif len(candidates) > 1:
72+
elif len(candidates) == 1:
73+
return candidates[0]
74+
elif key in candidates:
75+
return key
76+
else:
7377
out.error(
7478
'Ambiguous command: %s' % key,
7579
'Candidates are: %s' % ', '.join(candidates),
7680
)
7781
sys.exit(utils.STGIT_GENERAL_ERROR)
7882

79-
return candidates[0]
80-
8183
def __getitem__(self, key):
8284
cmd_mod = self.get(key) or self.get(self.canonical_cmd(key))
8385
if is_cmd_alias(cmd_mod):

t/t0004-main.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ test_expect_success 'Test help on ambiguous command' '
3737
grep -e "Ambiguous command: pu"
3838
'
3939

40+
test_expect_success 'Test ambiguous alias' '
41+
test_config stgit.alias.show-stat "git show --stat" &&
42+
stg show-stat &&
43+
stg init &&
44+
stg show &&
45+
general_error stg sho 2>&1 | grep -e "Ambiguous command: sho"
46+
'
47+
4048
test_expect_success 'Test version/--version equivalence' '
4149
stg version > v0.txt &&
4250
stg --version > v1.txt &&

0 commit comments

Comments
 (0)