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

[PATCH] t9902: Instruct git-completion.bash about a test mode

From
Jean-Noël AVILA <jn.avila@free.fr>
Date
Jan 24, 2013, 21:20 UTC
Message-ID
<201301242220.09067.jn.avila@free.fr>

In test mode, git completion should propose commands only if they belong to the list of authorized commands.

Signed-off-by: Jean-Noel Avila <jn.avila@free.fr>
---

Better show some code than try to explain. Here is what I mean by "filter the output git help -a".

 contrib/completion/git-completion.bash | 16 +++++++++++++++-
 t/t9902-completion.sh                  |  4 ++--
 2 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 14dd5e7..6490553 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -531,6 +531,20 @@ __git_complete_strategy ()
 	return 1
 }
 
+if test -z "$AUTHORIZED_CMD_LIST"; then
+	__git_cmdlist ()
+	{ 
+		echo $1;
+	}
+else
+	__git_cmdlist ()
+	{ 
+		if [[ " $AUTHORIZED_CMD_LIST " =~ " $1 " ]] ; then
+				echo $1
+		fi
+	}
+fi
+
 __git_list_all_commands ()
 {
 	local i IFS=" "$'\n'
@@ -538,7 +552,7 @@ __git_list_all_commands ()
 	do
 		case $i in
 		*--*)             : helper pattern;;
-		*) echo $i;;
+		*) __git_cmdlist $i;;
 		esac
 	done
 }
diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh
index 3cd53f8..5e7d81e 100755
--- a/t/t9902-completion.sh
+++ b/t/t9902-completion.sh
@@ -12,8 +12,8 @@ complete ()
 	# do nothing
 	return 0
 }
-
-. "$GIT_BUILD_DIR/contrib/completion/git-completion.bash"
+AUTHORIZED_CMD_LIST=" checkout show add filter-branch ls-files send-email describe"
+. "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" 
 
 # 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 5 in “t9902: Instruct git-completion.bash about a test mode”
  1. t9902: Instruct git-completion.bash about a test modeJean-Noël AVILA, Jan 24, 2013
  2. Junio C HamanoJan 24, 2013
  3. Jean-Noël AVILAJan 24, 2013
  4. Junio C HamanoJan 24, 2013
  5. Jean-Noël AVILAJan 24, 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.