git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] completion: fix completion of certain aliases

From
SZEDER Gábor <szeder@ira.uka.de>
Date
Dec 13, 2013, 14:16 UTC
Message-ID
<20131213141624.GA28369@goldbirke>
In-Reply-To
<1386421873-27863-1-git-send-email-felipe.contreras@gmail.com>
Hi,
On Sat, Dec 07, 2013 at 07:11:13AM -0600, Felipe Contreras wrote:
> Some commands need the first word to determine the actual action that is
> being executed, however, the command is wrong when we use an alias,

This first sentence was hard to understand for me because of the wrong terminology used. How about this instead:

  Some completion helper functions need to know the name of the git
  command to act properly.  However, ...
> for
> example 'alias.p=push', if we try to complete 'git p origin ', the
> result would be wrong because __git_complete_remote_or_refspec() doesn't
> know where it come from.

Are there other helper functions that are affected? After a quick glance I didn't find any. In this case we could even write the above as

  The __git_complete_remote_or_refspec() completion helper function
  needs to know ...
> So let's override words[1], so the alias 'p' is override by the actual
> command, 'push'.

words[1] is not always the name of the git command, it can also be an option to the main git command, e.g. in case of 'git -c key=value push ...' with this patch '-c' would be overwritten.

Best, Gábor

Show 35 quoted lines
> Reported-by: Aymeric Beaumet <aymeric.beaumet@gmail.com>
> Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
> ---
>  contrib/completion/git-completion.bash | 1 +
>  contrib/completion/git-completion.zsh  | 1 +
>  2 files changed, 2 insertions(+)
> 
> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
> index dba3c15..c14bac4 100644
> --- a/contrib/completion/git-completion.bash
> +++ b/contrib/completion/git-completion.bash
> @@ -2530,6 +2530,7 @@ __git_main ()
>  
>  	local expansion=$(__git_aliased_command "$command")
>  	if [ -n "$expansion" ]; then
> +		words[1]=$expansion
>  		completion_func="_git_${expansion//-/_}"
>  		declare -f $completion_func >/dev/null && $completion_func
>  	fi
> diff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh
> index fac5e71..3eeb7f8 100644
> --- a/contrib/completion/git-completion.zsh
> +++ b/contrib/completion/git-completion.zsh
> @@ -96,6 +96,7 @@ __git_zsh_bash_func ()
>  
>  	local expansion=$(__git_aliased_command "$command")
>  	if [ -n "$expansion" ]; then
> +		words[1]=$expansion
>  		completion_func="_git_${expansion//-/_}"
>  		declare -f $completion_func >/dev/null && $completion_func
>  	fi
> -- 
> 1.8.4.2+fc1
> 
> 
Previous: Felipe Contreras
Message 2 of 2 in “completion: fix completion of certain aliases”
  1. completion: fix completion of certain aliasesFelipe Contreras, Dec 7, 2013
  2. SZEDER GáborDec 13, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.