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

[PATCH v3] repo: show subcommand-specific help text

From
Mahi Kassa <mahlet.takassa@gmail.com>
Date
Mar 24, 2026, 18:48 UTC
Message-ID
<20260324184843.299223-1-mahlet.takassa@gmail.com>
In-Reply-To
<20260323152937.257406-1-mahlet.takassa@gmail.com>

Use subcommand-specific usage arrays for "git repo info" and "git repo structure" so that each command shows only its own synopsis in help output.

Factor the shared usage strings into macros to avoid duplicating the same synopsis text in multiple arrays.

Add tests to cover the subcommand help behavior.

The previous reroll mistakenly omitted the requested code changes; this version includes them.

---
v3:
- include the requested code changes that were missing from v2
- factor shared usage strings into macros to avoid duplication
- restore blank lines between tests and before test_done
 builtin/repo.c            | 28 ++++++++++++++++++++++------
 t/t1900-repo-info.sh      |  6 ++++++
 t/t1901-repo-structure.sh |  6 ++++++
 3 files changed, 34 insertions(+), 6 deletions(-)
diff --git a/builtin/repo.c b/builtin/repo.c
index 55f9b9095c..71a5c1c29c 100644
--- a/builtin/repo.c
+++ b/builtin/repo.c
@@ -20,11 +20,27 @@
 #include "tree-walk.h"
 #include "utf8.h"
 
+#define REPO_INFO_USAGE \
+	"git repo info [--format=(lines|nul) | -z] [--all | <key>...]", \
+	"git repo info --keys [--format=(lines|nul) | -z]"
+
+#define REPO_STRUCTURE_USAGE \
+	"git repo structure [--format=(table|lines|nul) | -z]"
+
 static const char *const repo_usage[] = {
-	"git repo info [--format=(lines|nul) | -z] [--all | <key>...]",
-	"git repo info --keys [--format=(lines|nul) | -z]",
-	"git repo structure [--format=(table|lines|nul) | -z]",
-	NULL
+	REPO_INFO_USAGE,
+	REPO_STRUCTURE_USAGE,
+	NULL,
+};
+
+static const char *const repo_info_usage[] = {
+	REPO_INFO_USAGE,
+	NULL,
+};
+
+static const char *const repo_structure_usage[] = {
+	REPO_STRUCTURE_USAGE,
+	NULL,
 };
 
 typedef int get_value_fn(struct repository *repo, struct strbuf *buf);
@@ -214,7 +230,7 @@ static int cmd_repo_info(int argc, const char **argv, const char *prefix,
 		OPT_END()
 	};
 
-	argc = parse_options(argc, argv, prefix, options, repo_usage, 0);
+	argc = parse_options(argc, argv, prefix, options, repo_info_usage, 0);
 
 	if (show_keys && (all_keys || argc))
 		die(_("--keys cannot be used with a <key> or --all"));
@@ -879,7 +895,7 @@ static int cmd_repo_structure(int argc, const char **argv, const char *prefix,
 		OPT_END()
 	};
 
-	argc = parse_options(argc, argv, prefix, options, repo_usage, 0);
+	argc = parse_options(argc, argv, prefix, options, repo_structure_usage, 0);
 	if (argc)
 		usage(_("too many arguments"));
 
diff --git a/t/t1900-repo-info.sh b/t/t1900-repo-info.sh
index a9eb07abe8..39bb77dda0 100755
--- a/t/t1900-repo-info.sh
+++ b/t/t1900-repo-info.sh
@@ -149,4 +149,10 @@ test_expect_success 'git repo info --keys uses lines as its default output forma
 	test_cmp expect actual
 '
 
+test_expect_success 'git repo info -h shows only repo info usage' '
+	test_must_fail git repo info -h >actual &&
+	test_grep "git repo info" actual &&
+	test_grep ! "git repo structure" actual
+'
+
 test_done
diff --git a/t/t1901-repo-structure.sh b/t/t1901-repo-structure.sh
index 98921ce1cb..10050abd70 100755
--- a/t/t1901-repo-structure.sh
+++ b/t/t1901-repo-structure.sh
@@ -224,4 +224,10 @@ test_expect_success 'progress meter option' '
 	)
 '
 
+test_expect_success 'git repo structure -h shows only repo structure usage' '
+	test_must_fail git repo structure -h >actual &&
+	test_grep "git repo structure" actual &&
+	test_grep ! "git repo info" actual
+'
+
 test_done
-- 
2.34.1
Previous: Derrick StoleeNext: Derrick Stolee
Message 7 of 10 in “repo: show subcommand-specific help text”
  1. repo: show subcommand-specific help textMahi Kassa, Mar 23, 2026
  2. Derrick StoleeMar 23, 2026
  3. Patrick SteinhardtMar 24, 2026
  4. repo: show subcommand-specific help textMahi Kassa, Mar 24, 2026
  5. Patrick SteinhardtMar 24, 2026
  6. Derrick StoleeMar 24, 2026
  7. repo: show subcommand-specific help textMahi Kassa, Mar 24, 2026
  8. Derrick StoleeMar 24, 2026
  9. Patrick SteinhardtMar 25, 2026
  10. Junio C HamanoMar 25, 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.