{"thread":{"id":"35495","subject":"[PATCH] completion: fix completion of certain aliases","startedAt":"2013-12-07T13:11:13Z","lastAt":"2013-12-13T14:16:24Z","messageCount":2,"participants":["Felipe Contreras","SZEDER Gábor"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"231706","messageId":"1386421873-27863-1-git-send-email-felipe.contreras@gmail.com","threadId":"35495","inReplyTo":null,"subject":"[PATCH] completion: fix completion of certain aliases","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2013-12-07T13:11:13Z","receivedAt":"2013-12-07T13:11:13Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"Some commands need the first word to determine the actual action that is\nbeing executed, however, the command is wrong when we use an alias, for\nexample 'alias.p=push', if we try to complete 'git p origin ', the\nresult would be wrong because __git_complete_remote_or_refspec() doesn't\nknow where it come from.\n\nSo let's override words[1], so the alias 'p' is override by the actual\ncommand, 'push'.\n\nReported-by: Aymeric Beaumet <aymeric.beaumet@gmail.com>\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n contrib/completion/git-completion.bash | 1 +\n contrib/completion/git-completion.zsh  | 1 +\n 2 files changed, 2 insertions(+)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex dba3c15..c14bac4 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -2530,6 +2530,7 @@ __git_main ()\n \n \tlocal expansion=$(__git_aliased_command \"$command\")\n \tif [ -n \"$expansion\" ]; then\n+\t\twords[1]=$expansion\n \t\tcompletion_func=\"_git_${expansion//-/_}\"\n \t\tdeclare -f $completion_func >/dev/null && $completion_func\n \tfi\ndiff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh\nindex fac5e71..3eeb7f8 100644\n--- a/contrib/completion/git-completion.zsh\n+++ b/contrib/completion/git-completion.zsh\n@@ -96,6 +96,7 @@ __git_zsh_bash_func ()\n \n \tlocal expansion=$(__git_aliased_command \"$command\")\n \tif [ -n \"$expansion\" ]; then\n+\t\twords[1]=$expansion\n \t\tcompletion_func=\"_git_${expansion//-/_}\"\n \t\tdeclare -f $completion_func >/dev/null && $completion_func\n \tfi\n-- \n1.8.4.2+fc1\n"},{"id":"231974","messageId":"20131213141624.GA28369@goldbirke","threadId":"35495","inReplyTo":"1386421873-27863-1-git-send-email-felipe.contreras@gmail.com","subject":"Re: [PATCH] completion: fix completion of certain aliases","fromName":"SZEDER Gábor","fromEmail":"szeder@ira.uka.de","sentAt":"2013-12-13T14:16:24Z","receivedAt":"2013-12-13T14:16:24Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"Hi,\n\nOn Sat, Dec 07, 2013 at 07:11:13AM -0600, Felipe Contreras wrote:\n> Some commands need the first word to determine the actual action that is\n> being executed, however, the command is wrong when we use an alias,\n\nThis first sentence was hard to understand for me because of the wrong\nterminology used.  How about this instead:\n\n  Some completion helper functions need to know the name of the git\n  command to act properly.  However, ...\n\n> for\n> example 'alias.p=push', if we try to complete 'git p origin ', the\n> result would be wrong because __git_complete_remote_or_refspec() doesn't\n> know where it come from.\n\nAre there other helper functions that are affected?  After a quick\nglance I didn't find any.  In this case we could even write the above\nas\n\n  The __git_complete_remote_or_refspec() completion helper function\n  needs to know ...\n\n\n> So let's override words[1], so the alias 'p' is override by the actual\n> command, 'push'.\n\nwords[1] is not always the name of the git command, it can also be an\noption to the main git command, e.g. in case of 'git -c key=value push\n...' with this patch '-c' would be overwritten.\n\n\nBest,\nGábor\n\n> Reported-by: Aymeric Beaumet <aymeric.beaumet@gmail.com>\n> Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n> ---\n>  contrib/completion/git-completion.bash | 1 +\n>  contrib/completion/git-completion.zsh  | 1 +\n>  2 files changed, 2 insertions(+)\n> \n> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\n> index dba3c15..c14bac4 100644\n> --- a/contrib/completion/git-completion.bash\n> +++ b/contrib/completion/git-completion.bash\n> @@ -2530,6 +2530,7 @@ __git_main ()\n>  \n>  \tlocal expansion=$(__git_aliased_command \"$command\")\n>  \tif [ -n \"$expansion\" ]; then\n> +\t\twords[1]=$expansion\n>  \t\tcompletion_func=\"_git_${expansion//-/_}\"\n>  \t\tdeclare -f $completion_func >/dev/null && $completion_func\n>  \tfi\n> diff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh\n> index fac5e71..3eeb7f8 100644\n> --- a/contrib/completion/git-completion.zsh\n> +++ b/contrib/completion/git-completion.zsh\n> @@ -96,6 +96,7 @@ __git_zsh_bash_func ()\n>  \n>  \tlocal expansion=$(__git_aliased_command \"$command\")\n>  \tif [ -n \"$expansion\" ]; then\n> +\t\twords[1]=$expansion\n>  \t\tcompletion_func=\"_git_${expansion//-/_}\"\n>  \t\tdeclare -f $completion_func >/dev/null && $completion_func\n>  \tfi\n> -- \n> 1.8.4.2+fc1\n> \n> \n"}]}