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

[PATCHv2 2/2] completion: fix alias listings with newlines

From
Stephen Boyd <bebarino@gmail.com>
Date
Oct 9, 2009, 06:21 UTC
Message-ID
<1255069304-8953-2-git-send-email-bebarino@gmail.com>
In-Reply-To
<1255069304-8953-1-git-send-email-bebarino@gmail.com>

Aliases with newlines have been a problem since commit 56fc25f (Bash completion support for remotes in .git/config., 2006-11-05). The chance of the problem occurring has been slim at best, until commit 518ef8f (completion: Replace config --list with --get-regexp, 2009-09-11) removed the case statement introduced by commit 56fc25f. Before removing the case statement, most aliases with newlines would work unless they were specially crafted as follows

[alias]
	foo = "log -1 --pretty='format:%s\nalias.error=broken'"
After removing the case statement, a more benign alias like
[alias]
	whowhat = "log -1 --pretty='format:%an <%ae>\n%s'"
	wont-complete = ...
would cause the completion to break badly.

For now, revert the removal of the case statement until someone comes up with a better way to get keys from git-config.

Signed-off-by: Stephen Boyd <bebarino@gmail.com>
---
This is an alternate fix to my previous 1/3 patch.

Hannes has convinced me to go this route. I don't really see a problem, it basically reverts to broken behavior that nobody's complained about in 3 years. At least it's less broken?

 contrib/completion/git-completion.bash |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 652a47c..e482c8d 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -602,8 +602,12 @@ __git_aliases ()
 {
 	local i IFS=$'\n'
 	for i in $(git --git-dir="$(__gitdir)" config --get-regexp "alias\..*" 2>/dev/null); do
-		i="${i#alias.}"
-		echo "${i/ */}"
+		case "$i" in
+		alias.*)
+			i="${i#alias.}"
+			echo "${i/ */}"
+			;;
+		esac
 	done
 }
 
-- 
1.6.5.rc3
Previous: Stephen BoydNext: Shawn O. Pearce
Message 2 of 4 in “completion: fix completion of git <TAB><TAB>”
  1. 1/2 completion: fix completion of git <TAB><TAB>Stephen Boyd, Oct 9, 2009
  2. 2/2 completion: fix alias listings with newlinesStephen Boyd, Oct 9, 2009
  3. Shawn O. PearceOct 9, 2009
  4. Shawn O. PearceOct 9, 2009

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.