advice: use global config for default branch name
PATCH v2 1/1 advice: use global config for default branch name
The advice for configuring the default branch name suggests disabling it with "git config set advice.defaultBranchName false". This setting is useless because it neither affects the current repository nor newly created repositories.
Suggest using "git config set --global" instead.
To implement this, add a "global_hint" field to the advice_setting struct and explicitly set it to true for defaultBranchName to indicate that the advice should recommend a global configuration. This field can also be used for other advice settings if needed.
Signed-off-by Vsevolod Myalitsin <[email protected]>
--- advice.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
advice.c +8 -6
@@ -42,6 +42,7 @@ enum advice_level {static struct {const char *key; +bool global_hint;enum advice_level level; } advice_setting[] = { [ADVICE_ADD_EMBEDDED_REPO ] = {"addEmbeddedRepo" },
@@ -51,7 +52,7 @@ static struct { [ADVICE_AM_WORK_DIR] = { "amWorkDir" }, [ADVICE_CHECKOUT_AMBIGUOUS_REMOTE_BRANCH_NAME] = { "checkoutAmbiguousRemoteBranchName" }, [ADVICE_COMMIT_BEFORE_MERGE] = { "commitBeforeMerge" }, - [ADVICE_DEFAULT_BRANCH_NAME] = { "defaultBranchName" }, + [ADVICE_DEFAULT_BRANCH_NAME] = { "defaultBranchName", true }, [ADVICE_DETACHED_HEAD] = { "detachedHead" }, [ADVICE_DIVERGING] = { "diverging" }, [ADVICE_FETCH_SET_HEAD_WARN] = { "fetchRemoteHEADWarn" },
@@ -96,10 +97,10 @@ static struct {static const char turn_off_instructions[] =N_ ("\n" -"Disable this message with \"git config set advice.%s false\"" ); +"Disable this message with \"git config set%s advice.%s false\"" );static void vadvise (const char *advice,int display_instructions, -const char *key,va_list params) +const char *key,bool global_hint,va_list params) {struct strbuf buf =STRBUF_INIT ;const char *cp, *np;
@@ -107,7 +108,8 @@ static void vadvise(const char *advice, int display_instructions,strbuf_vaddf (&buf, advice, params);if (display_instructions) -strbuf_addf (&buf, turn_off_instructions, key); +strbuf_addf (&buf, turn_off_instructions, global_hint ? +" --global" :"" , key);for (cp = buf.buf; *cp; cp = np) { np =strchrnul (cp,'\n' );
@@ -126,7 +128,7 @@ void advise(const char *advice, ...) {va_list params;va_start (params, advice); -vadvise (advice,0 ,"" , params); +vadvise (advice,0 ,"" , false, params);va_end (params); }
@@ -156,7 +158,7 @@ void advise_if_enabled(enum advice_type type, const char *advice, ...)va_start (params, advice);vadvise (advice, !advice_setting[type].level, advice_setting[type].key, - params); + advice_setting[type].global_hint, params);va_end (params); }
Signature · 1 line
2.50.1