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

[RFC] Instruct git-completion.bash that we are in test mode

From
Jean-Noël AVILA <jn.avila@free.fr>
Date
Jan 21, 2013, 22:30 UTC
Message-ID
<201301212330.10824.jn.avila@free.fr>
In test mode, git completion should only propose core commands.
Signed-off-by: Jean-Noel Avila <jn.avila@free.fr>
---

I reworked the patch so that the test argument is only evaluated when sourcing the file and there is no environment clutter.

At least, "it works for me".
 contrib/completion/git-completion.bash | 8 +++++++-
 t/t9902-completion.sh                  | 2 +-
 2 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 14dd5e7..ac9fa65 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -531,10 +531,16 @@ __git_complete_strategy ()
 	return 1
 }
 
+if [ "x$1" != "xTEST" ]; then
+	__git_cmdlist () { git help -a|egrep '^  [a-zA-Z0-9]'; }
+else
+	__git_cmdlist () { git help -a| egrep -m 1 -B1000 PATH | egrep '^  [a-zA-Z0-9]'; }
+fi
+
 __git_list_all_commands ()
 {
 	local i IFS=" "$'\n'
-	for i in $(git help -a|egrep '^  [a-zA-Z0-9]')
+	for i in $(__git_cmdlist)
 	do
 		case $i in
 		*--*)             : helper pattern;;
diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh
index 3cd53f8..51463b2 100755
--- a/t/t9902-completion.sh
+++ b/t/t9902-completion.sh
@@ -13,7 +13,7 @@ complete ()
 	return 0
 }
 
-. "$GIT_BUILD_DIR/contrib/completion/git-completion.bash"
+. "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" TEST
 
 # We don't need this function to actually join words or do anything special.
 # Also, it's cleaner to avoid touching bash's internal completion variables.
-- 
1.8.1.1.271.g02f55e6
Next: Junio C Hamano
Message 1 of 15 in “[RFC] Instruct git-completion.bash that we are in test mode”
  1. Jean-Noël AVILAJan 21, 2013
  2. Junio C HamanoJan 21, 2013
  3. Jeff KingJan 22, 2013
  4. Junio C HamanoJan 22, 2013
  5. Jean-Noël AvilaJan 22, 2013
  6. Junio C HamanoJan 22, 2013
  7. t9902: protect test from stray build artifactsJunio C Hamano, Jan 24, 2013
  8. Jeff KingJan 25, 2013
  9. Jonathan NiederJan 25, 2013
  10. Junio C HamanoJan 25, 2013
  11. Jeff KingJan 25, 2013
  12. Junio C HamanoJan 25, 2013
  13. Jeff KingJan 25, 2013
  14. Junio C HamanoJan 25, 2013
  15. Jeff KingJan 25, 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.