From b79deeb55444f9e01a3f6335d7e0507e23e90190 Mon Sep 17 00:00:00 2001 From: James Liu Date: Fri, 3 May 2024 17:17:06 +1000 Subject: advice: add --no-advice global option Advice hints must be disabled individually by setting the relevant advice.* variables to false in the Git configuration. For server-side and scripted usages of Git where hints can be a hindrance, it can be cumbersome to maintain configuration to ensure all advice hints are disabled in perpetuity. This is a particular concern in tests, where new or changed hints can result in failed assertions. Add a --no-advice global option to disable all advice hints from being displayed. This is independent of the toggles for individual advice hints. Use an internal environment variable (GIT_ADVICE) to ensure this configuration is propagated to the usage site, even if it executes in a subprocess. Signed-off-by: James Liu Signed-off-by: Junio C Hamano --- git.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'git.c') diff --git a/git.c b/git.c index 7654571b75..637c61ca9c 100644 --- a/git.c +++ b/git.c @@ -37,8 +37,9 @@ const char git_usage_string[] = N_("git [-v | --version] [-h | --help] [-C ] [-c =]\n" " [--exec-path[=]] [--html-path] [--man-path] [--info-path]\n" " [-p | --paginate | -P | --no-pager] [--no-replace-objects] [--no-lazy-fetch]\n" - " [--no-optional-locks] [--bare] [--git-dir=] [--work-tree=]\n" - " [--namespace=] [--config-env==] []"); + " [--no-optional-locks] [--no-advice] [--bare] [--git-dir=]\n" + " [--work-tree=] [--namespace=] [--config-env==]\n" + " []"); const char git_more_info_string[] = N_("'git help -a' and 'git help -g' list available subcommands and some\n" @@ -337,6 +338,10 @@ static int handle_options(const char ***argv, int *argc, int *envchanged) setenv(GIT_ATTR_SOURCE_ENVIRONMENT, cmd, 1); if (envchanged) *envchanged = 1; + } else if (!strcmp(cmd, "--no-advice")) { + setenv(GIT_ADVICE_ENVIRONMENT, "0", 1); + if (envchanged) + *envchanged = 1; } else { fprintf(stderr, _("unknown option: %s\n"), cmd); usage(git_usage_string); -- cgit v1.2.3