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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxx>
---
 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



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux