Skip to content

Commit 6131807

Browse files
Denton-Lgitster
authored andcommitted
git-completion.bash: use __gitcomp_builtin() in _git_stash()
The completion for 'git stash' has not changed in a major way since it was converted from shell script to builtin. Now that it's a builtin, we can take advantage of the groundwork laid out by parse-options and use the generated options. Rewrite _git_stash() to take use __gitcomp_builtin() to generate completions for subcommands. The main `git stash` command does not take any arguments directly. If no subcommand is given, it automatically defaults to `git stash push`. This means that we can simplify the logic for when no subcommands have been given yet. We only have to offer subcommand completions when we're completing a non-option after "stash". One area that this patch could improve upon is that the `git stash list` command accepts log-options. It would be nice if the completion for this were unified with that of _git_log() and _git_show() which would allow completions to be provided for options such as `--pretty` but that is outside the scope of this patch. Signed-off-by: Denton Liu <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 42b30bc commit 6131807

File tree

1 file changed

+20
-22
lines changed

1 file changed

+20
-22
lines changed

contrib/completion/git-completion.bash

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3013,51 +3013,49 @@ _git_sparse_checkout ()
30133013

30143014
_git_stash ()
30153015
{
3016-
local save_opts='--all --keep-index --no-keep-index --quiet --patch --include-untracked'
30173016
local subcommands='push list show apply clear drop pop create branch'
30183017
local subcommand="$(__git_find_on_cmdline "$subcommands save")"
3019-
if [ -z "$subcommand" -a -n "$(__git_find_on_cmdline "-p")" ]; then
3020-
subcommand="push"
3021-
fi
3018+
30223019
if [ -z "$subcommand" ]; then
3023-
case "$cur" in
3024-
--*)
3025-
__gitcomp "$save_opts"
3020+
case "$((cword - __git_subcommand_idx)),$cur" in
3021+
*,--*)
3022+
__gitcomp_builtin stash_push
30263023
;;
3027-
sa*)
3028-
if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
3029-
__gitcomp "save"
3030-
fi
3024+
1,sa*)
3025+
__gitcomp "save"
30313026
;;
3032-
*)
3033-
if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
3034-
__gitcomp "$subcommands"
3035-
fi
3027+
1,*)
3028+
__gitcomp "$subcommands"
30363029
;;
30373030
esac
30383031
return
30393032
fi
30403033

30413034
case "$subcommand,$cur" in
30423035
push,--*)
3043-
__gitcomp "$save_opts --message"
3036+
__gitcomp_builtin stash_push
30443037
;;
30453038
save,--*)
3046-
__gitcomp "$save_opts"
3039+
__gitcomp_builtin stash_save
3040+
;;
3041+
pop,--*)
3042+
__gitcomp_builtin stash_pop
30473043
;;
3048-
apply,--*|pop,--*)
3049-
__gitcomp "--index --quiet"
3044+
apply,--*)
3045+
__gitcomp_builtin stash_apply
30503046
;;
30513047
drop,--*)
3052-
__gitcomp "--quiet"
3048+
__gitcomp_builtin stash_drop
30533049
;;
30543050
list,--*)
3055-
__gitcomp "--name-status --oneline --patch-with-stat"
3051+
# NEEDSWORK: can we somehow unify this with the options in _git_log() and _git_show()
3052+
__gitcomp_builtin stash_list "$__git_log_common_options $__git_diff_common_options"
30563053
;;
30573054
show,--*)
3058-
__gitcomp "$__git_diff_common_options"
3055+
__gitcomp_builtin stash_show "$__git_diff_common_options"
30593056
;;
30603057
branch,--*)
3058+
__gitcomp_builtin stash_branch
30613059
;;
30623060
branch,*)
30633061
if [ $cword -eq $((__git_subcommand_idx+2)) ]; then

0 commit comments

Comments
 (0)