[PATCH v2 1/5] completion: simplify stash subcommand completion
- From
D. Ben Knoble <ben.knoble@gmail.com>
- Date
- Oct 23, 2026, 13:20 UTC
- Message-ID
- <90d36b64450a21e9afed62c66fd3f72e4c4d429f.1792761643.git.ben.knoble@gmail.com>
- In-Reply-To
- <cover.1792761643.git.ben.knoble@gmail.com>
The stash completion helper contains a hard-coded list of commands, but git-stash provides a mechanism to list such commands (--git-completion-helper). The pattern for using it is wrapped by __git_resolve_builtins, so use it, bringing _git_stash closer in line with other completion helpers. As a nice side-benefit, this also adds "store" subcommand completion, which is missing from the explicit list of subcommands.
Note that we maintain the "save" special case†, since it was removed from default completion in 0eb5a4f911 (completion: stop showing 'save' for stash by default, 2018-04-20). One might think we need to give "save" to __git_resolve_builtins' 3rd exclude argument to prevent it from showing up, but we don't: "save" is already marked PARSE_OPT_NOCOMPLETE.
†We don't complete the "save" subcommand unless at least "sa" has been typed, but we do complete its options if explicitly typed. With this change, we will complete "save" if GIT_COMPLETION_SHOW_ALL=1.
Signed-off-by: D. Ben Knoble <ben.knoble@gmail.com> --- contrib/completion/git-completion.bash | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index c3a49e2e22..d60e85479c 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -3553,8 +3553,12 @@ _git_sparse_checkout () _git_stash () { - local subcommands='push list show apply clear drop pop create branch import export' - local subcommand="$(__git_find_on_cmdline "$subcommands save")" + local subcommands subcommand + + __git_resolve_builtins stash + + subcommands="$___git_resolved_builtins" + subcommand="$(__git_find_on_cmdline "$subcommands save")" if [ -z "$subcommand" ]; then case "$((cword - __git_cmd_idx)),$cur" in
-- 2.56.0.237.g5414b88716.dirty