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 <james@jamesliu.io> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
5bd8811a73
commit
b79deeb554
7
advice.c
7
advice.c
@ -2,6 +2,7 @@
|
||||
#include "advice.h"
|
||||
#include "config.h"
|
||||
#include "color.h"
|
||||
#include "environment.h"
|
||||
#include "gettext.h"
|
||||
#include "help.h"
|
||||
#include "string-list.h"
|
||||
@ -127,6 +128,12 @@ void advise(const char *advice, ...)
|
||||
int advice_enabled(enum advice_type type)
|
||||
{
|
||||
int enabled = advice_setting[type].level != ADVICE_LEVEL_DISABLED;
|
||||
static int globally_enabled = -1;
|
||||
|
||||
if (globally_enabled < 0)
|
||||
globally_enabled = git_env_bool(GIT_ADVICE_ENVIRONMENT, 1);
|
||||
if (!globally_enabled)
|
||||
return 0;
|
||||
|
||||
if (type == ADVICE_PUSH_UPDATE_REJECTED)
|
||||
return enabled &&
|
||||
|
Reference in New Issue
Block a user