From: René Scharfe Date: Tue, 17 Oct 2017 15:39:03 GMT Subject: [PATCH 1/2] git: add NO_INTERNAL_HELP flag for builtins 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 -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 --- 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 <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