]> git.ipfire.org Git - thirdparty/git.git/commit
git-completion.bash: use $__git_cmd_idx in more places
authorDenton Liu <liu.denton@gmail.com>
Thu, 22 Apr 2021 10:00:51 +0000 (03:00 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 27 Apr 2021 06:41:07 +0000 (15:41 +0900)
commit59d85a2a0528c3db2552b0786caac7bf0610c552
treefcc76fd969abbefb6fa4c8353684b65bbc827219
parent87e629756f3bbd5125237f504f12e394c576b26d
git-completion.bash: use $__git_cmd_idx in more places

With the introduction of the $__git_cmd_idx variable in e94fb44042
(git-completion.bash: pass $__git_subcommand_idx from __git_main(),
2021-03-24), completion functions were able to know the index at which
the git command is listed, allowing them to skip options that are given
to the underlying git itself, not the corresponding command (e.g.
`-C asdf` in `git -C asdf branch`).

While most of the changes here are self-explanatory, some bear further
explanation.

For the __git_find_on_cmdline() and __git_find_last_on_cmdline() pair of
functions, these functions are only ever called in the context of a git
command completion function. These functions will only care about words
after the command so we can safely ignore the words before this.

For _git_worktree(), this change is technically a no-op (once the
__git_find_last_on_cmdline change is also applied). It was in poor style
to have hard-coded on the index right after `worktree`. In case
`git worktree` were to ever learn to accept options, the current
situation would be inflexible.

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