git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] completion: fix completion of certain aliases
@ 2013-12-07 13:11 Felipe Contreras
  2013-12-13 14:16 ` SZEDER Gábor
  0 siblings, 1 reply; 2+ messages in thread
From: Felipe Contreras @ 2013-12-07 13:11 UTC (permalink / raw
  To: git; +Cc: Felipe Contreras

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, 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.

So let's override words[1], so the alias 'p' is override by the actual
command, 'push'.

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

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] completion: fix completion of certain aliases
  2013-12-07 13:11 [PATCH] completion: fix completion of certain aliases Felipe Contreras
@ 2013-12-13 14:16 ` SZEDER Gábor
  0 siblings, 0 replies; 2+ messages in thread
From: SZEDER Gábor @ 2013-12-13 14:16 UTC (permalink / raw
  To: Felipe Contreras; +Cc: git

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

> 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
> 
> 

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-12-13 14:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-12-07 13:11 [PATCH] completion: fix completion of certain aliases Felipe Contreras
2013-12-13 14:16 ` SZEDER Gábor

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).