Re: [PATCH 2/5] git-completion.bash: rename to $__git_cmd_idx
- From
SZEDER Gábor <szeder.dev@gmail.com>
- Date
- Apr 20, 2021, 21:14 UTC
- Message-ID
- <20210420211432.GA3842406@szeder.dev>
- In-Reply-To
- <xmqqr1j44r5g.fsf@gitster.g>
On Tue, Apr 20, 2021 at 01:50:19PM -0700, Junio C Hamano wrote:
Show 21 quoted lines
> Denton Liu <liu.denton@gmail.com> writes: > > > In e94fb44042 (git-completion.bash: pass $__git_subcommand_idx from > > __git_main(), 2021-03-24), the $__git_subcommand_idx variable was > > introduced. Naming it after the index of the subcommand is flat-out > > wrong as this variable really holds the index of the git comand (e.g. > > comand -> command > > > "stash"). > > > > Rename this variable so that it's obvious it's about git commands. While > > we're at it, shorten up its name so that it's still readable without > > being a handful to type. > > As the patch has already written, I won't complain too much, but to > many people "git" is a command and "add", "commit" etc. are > subcommands of "git", so I do not see git_subcommand_idx so wrong > that it needs to be renamed. I do understand that it is a bit too > long and it may be easier to type if renamed to say git_cmd_idx, > though ;-)
The completion functions for git commands having subcommands usually start like this:
_git_remote ()
{
local subcommands="
add rename remove set-head set-branches
get-url set-url show prune update
"
local subcommand="$(__git_find_on_cmdline "$subcommands")"
if [ -z "$subcommand" ]; then__git_subcommand_idx holds the index of the word "remote", not the index of "add/rename/etc.", so in the context of the completion script that name is misleading.