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

[PATCH 5/5] completion: fix completion of certain aliases

From
Felipe Contreras <felipe.contreras@gmail.com>
Date
Apr 9, 2014, 18:50 UTC
Message-ID
<1397069404-7451-6-git-send-email-felipe.contreras@gmail.com>
In-Reply-To
<1397069404-7451-1-git-send-email-felipe.contreras@gmail.com>

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 9525343..893ae5d 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -2547,6 +2547,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 6b77968..9f6f0fa 100644
--- a/contrib/completion/git-completion.zsh
+++ b/contrib/completion/git-completion.zsh
@@ -104,6 +104,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.9.1+fc1
Previous: Felipe ContrerasNext: Junio C Hamano
Message 6 of 8 in “Fixes”
  1. 0/5 FixesFelipe Contreras, Apr 9, 2014
  2. 1/5 remote-helpers: allow all tests running from any dirFelipe Contreras, Apr 9, 2014
  3. 2/5 remote-hg: always normalize pathsFelipe Contreras, Apr 9, 2014
  4. 3/5 remote-bzr: add support for older versionsFelipe Contreras, Apr 9, 2014
  5. 4/5 remote-bzr: include authors field in pushed commitsFelipe Contreras, Apr 9, 2014
  6. 5/5 completion: fix completion of certain aliasesFelipe Contreras, Apr 9, 2014
  7. Junio C HamanoApr 9, 2014
  8. Felipe ContrerasApr 9, 2014

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.