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

[PATCH 04/11] config-batch: create 'help' command

From
Derrick Stolee via GitGitGadget <gitgitgadget@gmail.com>
Date
Feb 4, 2026, 14:19 UTC
Message-ID
<d5e0c32497581e6ac4890c6e71c5c33b92d67d51.1770214803.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.2033.git.1770214803.gitgitgadget@gmail.com>
From: Derrick Stolee <stolee@gmail.com>

Tools that use the 'git config-batch' tool will want to know which commands are available in the current Git version. Having a 'help' command assists greatly to give a clear set of available commands and their versions.

Signed-off-by: Derrick Stolee <stolee@gmail.com>
---
 Documentation/git-config-batch.adoc | 17 +++++++++++++++
 builtin/config-batch.c              | 32 +++++++++++++++++++++++++++++
 t/t1312-config-batch.sh             | 13 ++++++++++++
 3 files changed, 62 insertions(+)
diff --git a/Documentation/git-config-batch.adoc b/Documentation/git-config-batch.adoc
index 31dd42f481..1fff68a13c 100644
--- a/Documentation/git-config-batch.adoc
+++ b/Documentation/git-config-batch.adoc
@@ -38,6 +38,23 @@ unknown_command LF
 
 These are the commands that are currently understood:
 
+`help` version 1::
+	The `help` command lists the currently-available commands in
+	this version of Git. The output is multi-line, but the first
+	line provides the count of possible commands via `help count <N>`.
+	The next `<N>` lines are of the form `help <command> <version>`
+	to state that this Git version supports that `<command>` at
+	version `<version>`. Note that the same command may have multiple
+	available versions.
++
+Here is the currentl output of the help text at the latest version:
++
+------------
+help 1 count 2
+help 1 help 1
+help 1 get 1
+------------
+
 `get` version 1::
 	The `get` command searches the config key-value pairs within a
 	given `<scope>` for values that match the fixed `<key>` and
diff --git a/builtin/config-batch.c b/builtin/config-batch.c
index 5782004080..1c19e4889f 100644
--- a/builtin/config-batch.c
+++ b/builtin/config-batch.c
@@ -12,6 +12,7 @@ static const char *const builtin_config_batch_usage[] = {
 };
 
 #define UNKNOWN_COMMAND "unknown_command"
+#define HELP_COMMAND "help"
 #define GET_COMMAND "get"
 #define COMMAND_PARSE_ERROR "command_parse_error"
 
@@ -104,6 +105,9 @@ static size_t parse_token(char **data, size_t *data_len,
 	return parse_whitespace_token(data, data_len, token, err);
 }
 
+static int help_command_1(struct repository *repo,
+			  char *data, size_t data_len);
+
 enum value_match_mode {
 	MATCH_ALL,
 	MATCH_EXACT,
@@ -302,6 +306,11 @@ struct command {
 };
 
 static struct command commands[] = {
+	{
+		.name = HELP_COMMAND,
+		.fn = help_command_1,
+		.version = 1,
+	},
 	{
 		.name = GET_COMMAND,
 		.fn = get_command_1,
@@ -316,6 +325,29 @@ static struct command commands[] = {
 
 #define COMMAND_COUNT ((size_t)(sizeof(commands) / sizeof(*commands)))
 
+static int help_command_1(struct repository *repo UNUSED,
+			  char *data UNUSED, size_t data_len UNUSED)
+{
+	struct strbuf fmt_str = STRBUF_INIT;
+
+	strbuf_addf(&fmt_str, "%"PRIu32, (uint32_t)(COMMAND_COUNT - 1));
+	emit_response(HELP_COMMAND, "1", "count", fmt_str.buf, NULL);
+	strbuf_reset(&fmt_str);
+
+	for (size_t i = 0; i < COMMAND_COUNT; i++) {
+		/* Halt at unknown command. */
+		if (!commands[i].name[0])
+			break;
+
+		strbuf_addf(&fmt_str, "%d", commands[i].version);
+		emit_response(HELP_COMMAND, "1", commands[i].name, fmt_str.buf, NULL);
+		strbuf_reset(&fmt_str);
+	}
+
+	strbuf_release(&fmt_str);
+	return 0;
+}
+
 /**
  * Process a single line from stdin and process the command.
  *
diff --git a/t/t1312-config-batch.sh b/t/t1312-config-batch.sh
index e638b54d13..6b550a0e76 100755
--- a/t/t1312-config-batch.sh
+++ b/t/t1312-config-batch.sh
@@ -23,6 +23,19 @@ test_expect_success 'completely broken input' '
 	test_grep "an unrecoverable error occurred during command execution" err
 '
 
+test_expect_success 'help command' '
+	echo "help 1" >in &&
+
+	cat >expect <<-\EOF &&
+	help 1 count 2
+	help 1 help 1
+	help 1 get 1
+	EOF
+
+	git config-batch >out <in &&
+	test_cmp expect out
+'
+
 test_expect_success 'failed to parse version' '
 	echo "bogus BAD_VERSION line of tokens" >in &&
 	test_must_fail git config-batch 2>err <in &&
-- 
gitgitgadget
Previous: Jean-Noël AvilaNext: Jean-Noël Avila
Message 14 of 40 in “[RFC] config-batch: a new builtin for tools querying config”
  1. 00/11 [RFC] config-batch: a new builtin for tools querying configDerrick Stolee via GitGitGadget, Feb 4, 2026
  2. 01/11 config-batch: basic boilerplate of new builtinDerrick Stolee via GitGitGadget, Feb 4, 2026
  3. Junio C HamanoFeb 4, 2026
  4. Derrick StoleeFeb 5, 2026
  5. Kristoffer HaugsbakkFeb 5, 2026
  6. Kristoffer HaugsbakkFeb 5, 2026
  7. Jean-Noël AvilaFeb 6, 2026
  8. 02/11 config-batch: create parse loop and unknown commandDerrick Stolee via GitGitGadget, Feb 4, 2026
  9. Junio C HamanoFeb 4, 2026
  10. Kristoffer HaugsbakkFeb 5, 2026
  11. Jean-Noël AvilaFeb 6, 2026
  12. 03/11 config-batch: implement get v1Derrick Stolee via GitGitGadget, Feb 4, 2026
  13. Jean-Noël AvilaFeb 6, 2026
  14. 04/11 config-batch: create 'help' commandDerrick Stolee via GitGitGadget, Feb 4, 2026
  15. Jean-Noël AvilaFeb 6, 2026
  16. Derrick StoleeFeb 10, 2026
  17. 05/11 config-batch: add NUL-terminated I/O formatDerrick Stolee via GitGitGadget, Feb 4, 2026
  18. Kristoffer HaugsbakkFeb 5, 2026
  19. Jean-Noël AvilaFeb 6, 2026
  20. 06/11 docs: add design doc for config-batchDerrick Stolee via GitGitGadget, Feb 4, 2026
  21. Kristoffer HaugsbakkFeb 5, 2026
  22. Derrick StoleeFeb 10, 2026
  23. 07/11 config: extract location structs from builtinDerrick Stolee via GitGitGadget, Feb 4, 2026
  24. 08/11 config-batch: pass prefix through commandsDerrick Stolee via GitGitGadget, Feb 4, 2026
  25. 09/11 config-batch: add 'set' v1 commandDerrick Stolee via GitGitGadget, Feb 4, 2026
  26. Kristoffer HaugsbakkFeb 5, 2026
  27. Kristoffer HaugsbakkFeb 5, 2026
  28. Kristoffer HaugsbakkFeb 5, 2026
  29. Derrick StoleeFeb 10, 2026
  30. Jean-Noël AvilaFeb 6, 2026
  31. 10/11 t1312: create read/write testDerrick Stolee via GitGitGadget, Feb 4, 2026
  32. 11/11 config-batch: add unset v1 commandDerrick Stolee via GitGitGadget, Feb 4, 2026
  33. Kristoffer HaugsbakkFeb 5, 2026
  34. Junio C HamanoFeb 4, 2026
  35. Derrick StoleeFeb 5, 2026
  36. brian m. carlsonFeb 5, 2026
  37. Derrick StoleeFeb 5, 2026
  38. Derrick StoleeFeb 10, 2026
  39. Phillip WoodFeb 5, 2026
  40. Kristoffer HaugsbakkFeb 5, 2026

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.