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

[PATCH 1/2] git: add NO_INTERNAL_HELP flag for builtins

From
René Scharfe <l.s.r@web.de>
Date
Oct 17, 2017, 15:39 UTC
Message-ID
<76c3e710-0655-7788-f6f4-af1e59d65edd@web.de>
In-Reply-To
<4d110305-0826-6fd1-91a5-c1ebd0b1e80b@web.de>

Builtin commands have skipped repo setup when called with just a single option -h and thus shown their short help text even outside of repositories since 99caeed05d3 (Let 'git <command> -h' show usage without a git dir).

Add the flag NO_INTERNAL_HELP for builtins to opt out of this special treatment and provide a list of commands that are exempt from the corresponding test in t0012. That allows builtins to handle -h themselves.

Signed-off-by: Rene Scharfe <l.s.r@web.de>
---
 git.c           | 6 +++++-
 t/t0012-help.sh | 9 ++++++++-
 2 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/git.c b/git.c
index 9e96dd4090..9d1b8c4716 100644
--- a/git.c
+++ b/git.c
@@ -298,6 +298,7 @@ static int handle_alias(int *argcp, const char ***argv)
 #define NEED_WORK_TREE		(1<<3)
 #define SUPPORT_SUPER_PREFIX	(1<<4)
 #define DELAY_PAGER_CONFIG	(1<<5)
+#define NO_INTERNAL_HELP	(1<<6)
 
 struct cmd_struct {
 	const char *cmd;
@@ -312,7 +313,10 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
 	const char *prefix;
 
 	prefix = NULL;
-	help = argc == 2 && !strcmp(argv[1], "-h");
+	if (p->option & NO_INTERNAL_HELP)
+		help = 0;
+	else
+		help = argc == 2 && !strcmp(argv[1], "-h");
 	if (!help) {
 		if (p->option & RUN_SETUP)
 			prefix = setup_git_directory();
diff --git a/t/t0012-help.sh b/t/t0012-help.sh
index 487b92a5de..74eeead168 100755
--- a/t/t0012-help.sh
+++ b/t/t0012-help.sh
@@ -53,12 +53,19 @@ test_expect_success 'generate builtin list' '
 	git --list-builtins >builtins
 '
 
+cat >no_internal_help <<EOF
+EOF
+
+test_expect_success 'generate list of builtins with internal help' '
+	grep -w -v -f no_internal_help <builtins >builtins_internal_help
+'
+
 while read builtin
 do
 	test_expect_success "$builtin can handle -h" '
 		test_expect_code 129 git $builtin -h >output 2>&1 &&
 		test_i18ngrep usage output
 	'
-done <builtins
+done <builtins_internal_help
 
 test_done
-- 
2.14.2
Previous: René ScharfeNext: Jonathan Nieder
Message 4 of 23 in “Bug: git ls-remote -h / --head results differ in output”
  1. Thomas RiklOct 15, 2017
  2. Martin ÅgrenOct 15, 2017
  3. René ScharfeOct 15, 2017
  4. 1/2 git: add NO_INTERNAL_HELP flag for builtinsRené Scharfe, Oct 17, 2017
  5. Jonathan NiederOct 17, 2017
  6. ls-remote: deprecate -h as short for --headsRené Scharfe, Oct 17, 2017
  7. Martin ÅgrenOct 17, 2017
  8. Jonathan NiederOct 17, 2017
  9. Junio C HamanoOct 17, 2017
  10. René ScharfeOct 19, 2017
  11. Jeff KingOct 19, 2017
  12. Junio C HamanoOct 20, 2017
  13. Jeff KingOct 20, 2017
  14. Junio C HamanoOct 20, 2017
  15. Jeff KingOct 21, 2017
  16. René ScharfeOct 21, 2017
  17. Junio C HamanoOct 21, 2017
  18. René ScharfeOct 23, 2017
  19. Junio C HamanoOct 24, 2017
  20. René ScharfeOct 24, 2017
  21. 2/2 ls-remote: use PARSE_OPT_NO_INTERNAL_HELPRené Scharfe, Oct 17, 2017
  22. Jonathan NiederOct 17, 2017
  23. Martin ÅgrenOct 17, 2017

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.