]> git.ipfire.org Git - thirdparty/git.git/commit
git-completion.bash: pass $__git_subcommand_idx from __git_main()
authorDenton Liu <liu.denton@gmail.com>
Wed, 24 Mar 2021 08:36:27 +0000 (01:36 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 24 Mar 2021 17:05:47 +0000 (10:05 -0700)
commite94fb4404280c07a668b4669c072983cdd079592
treef32840e03a63a1e3cef70d540d5f06f122c1196b
parenta5828ae6b52137b913b978e16cd2334482eb4c1f
git-completion.bash: pass $__git_subcommand_idx from __git_main()

Many completion functions perform hardcoded comparisons with $cword.
This fails in the case where the main git command is given arguments
(e.g. `git -C . bundle<TAB>` would fail to complete its subcommands).

Even _git_worktree(), which uses __git_find_on_cmdline(), could still
fail. With something like `git -C add worktree move<TAB>`, the
subcommand would be incorrectly identified as "add" instead of "move".

Assign $__git_subcommand_idx in __git_main(), where the git subcommand
is actually found and the corresponding completion function is called.
Use this variable to replace hardcoded comparisons with $cword.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
contrib/completion/git-completion.bash