Web lists-archives.com

Re: [PATCH] Add support for 'git remote rm' in Bash completion script

Hi Sergey,

There was a previous discussion of this in December 2017,
which might be useful:


It didn't end with a patch applied, but it's likely worth
reading to help you make a case for a similar patch.

One of the points in that thread is that the rm subcommand
is not shown in completion intentionally, as the preferred
subcommand is remove.  But it should be possible to offer
completion of the remotes after a user types rm, which I
imagine is the more helpful part of the completion.

Also, you'll want to add a signoff to the patch if/when you
resend it (refer to Documentation/SubmittingPatches, if you
haven't already).

Sergey Zolotarev wrote:
> ---
>  contrib/completion/git-completion.bash | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
> index 499e56f83d..fa25d689e2 100644
> --- a/contrib/completion/git-completion.bash
> +++ b/contrib/completion/git-completion.bash
> @@ -2334,7 +2334,7 @@ _git_remote ()
>  {
>  	local subcommands="
>  		add rename remove set-head set-branches
> -		get-url set-url show prune update
> +		get-url set-url show prune rm update
>  		"
>  	local subcommand="$(__git_find_on_cmdline "$subcommands")"

So instead of this change you could adjust the subcommand
line, something like:

-	local subcommand="$(__git_find_on_cmdline "$subcommands")"
+	# Don't advertise rm by including it in subcommands, but complete
+	# remotes if it is used.
+	local subcommand="$(__git_find_on_cmdline "$subcommands rm")"

I haven't test that, but the code looks like it hasn't
changed since the last time we talked about this -- when I
did test the suggestion :).

>  	if [ -z "$subcommand" ]; then
> @@ -2379,6 +2379,9 @@ _git_remote ()
>  	prune,--*)
>  		__gitcomp_builtin remote_prune
>  		;;
> +	rm,--*)
> +		__gitcomp_builtin remote_rm
> +		;;
>  	*)
>  		__gitcomp_nl "$(__git_remotes)"
>  		;;

I don't think you need this chunk, do you?  I think that's
only useful for completing options to the subcommand, which
'git remote rm' lacks.

I believe you can simply skip it and let the case fall
through to the last item which simply completes the
available remotes, just as 'git remote remove' does.

Hope that helps,