@@ -3016,6 +3016,9 @@ _git_stash ()
local save_opts='--all --keep-index --no-keep-index --quiet --patch --include-untracked'
local subcommands='push list show apply clear drop pop create branch'
local subcommand="$(__git_find_on_cmdline "$subcommands save")"
+ local stash_idx="$(__git_find_on_cmdline --show-idx stash)"
+ stash_idx="${stash_idx% *}"
+
if [ -z "$subcommand" -a -n "$(__git_find_on_cmdline "-p")" ]; then
subcommand="push"
fi
@@ -3060,7 +3063,7 @@ _git_stash ()
branch,--*)
;;
branch,*)
- if [ $cword -eq 3 ]; then
+ if [ $((cword - stash_idx)) -eq 2 ]; then
__git_complete_refs
else
__gitcomp_nl "$(__git stash list \
When completions are offered for `git stash branch<TAB>`, the user is supposed to receive refs. This works in the case where the main git command is called without arguments but if options are provided, such as `git -C dir stash branch<TAB>`, then the `$cword -eq 3` provides incorrect results. Count the words relative to the first instance of "stash" so that we ignore arguments to the main git command. Unfortunately, this still does not work 100% correctly. For example, in the case of something like `git -C stash stash branch<TAB>`, this will incorrectly identify the first "stash" as the command. This seems to be an edge-case that we can ignore, though, as other functions, such as _git_worktree(), suffer from the same problem. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- contrib/completion/git-completion.bash | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)