Skip to content

Commit ec0f362

Browse files
jltoblergitster
authored andcommitted
advice: allow disabling default branch name advice
The default branch name advice message is displayed when `repo_default_branch_name()` is invoked and the `init.defaultBranch` config is not set. In this scenario, the advice message is always shown even if the `--no-advice` option is used. Adapt `repo_default_branch_name()` to allow the default branch name advice message to be disabled with the `--no-advice` option and corresponding configuration. Signed-off-by: Justin Tobler <[email protected]> Acked-by: Phillip Wood <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c039a46 commit ec0f362

File tree

4 files changed

+12
-1
lines changed

4 files changed

+12
-1
lines changed

advice.c

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ static struct {
5151
[ADVICE_AM_WORK_DIR] = { "amWorkDir" },
5252
[ADVICE_CHECKOUT_AMBIGUOUS_REMOTE_BRANCH_NAME] = { "checkoutAmbiguousRemoteBranchName" },
5353
[ADVICE_COMMIT_BEFORE_MERGE] = { "commitBeforeMerge" },
54+
[ADVICE_DEFAULT_BRANCH_NAME] = { "defaultBranchName" },
5455
[ADVICE_DETACHED_HEAD] = { "detachedHead" },
5556
[ADVICE_DIVERGING] = { "diverging" },
5657
[ADVICE_FETCH_SET_HEAD_WARN] = { "fetchRemoteHEADWarn" },

advice.h

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ enum advice_type {
1818
ADVICE_AM_WORK_DIR,
1919
ADVICE_CHECKOUT_AMBIGUOUS_REMOTE_BRANCH_NAME,
2020
ADVICE_COMMIT_BEFORE_MERGE,
21+
ADVICE_DEFAULT_BRANCH_NAME,
2122
ADVICE_DETACHED_HEAD,
2223
ADVICE_DIVERGING,
2324
ADVICE_FETCH_SET_HEAD_WARN,

refs.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,8 @@ char *repo_default_branch_name(struct repository *r, int quiet)
664664
if (!ret) {
665665
ret = xstrdup("master");
666666
if (!quiet)
667-
advise(_(default_branch_name_advice), ret);
667+
advise_if_enabled(ADVICE_DEFAULT_BRANCH_NAME,
668+
_(default_branch_name_advice), ret);
668669
}
669670

670671
full_ref = xstrfmt("refs/heads/%s", ret);

t/t0001-init.sh

+8
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,14 @@ test_expect_success 'advice on unconfigured init.defaultBranch' '
830830
test_grep "<YELLOW>hint: " decoded
831831
'
832832

833+
test_expect_success 'advice on unconfigured init.defaultBranch disabled' '
834+
test_when_finished "rm -rf no-advice" &&
835+
836+
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \
837+
git -c advice.defaultBranchName=false init no-advice 2>err &&
838+
test_grep ! "hint: " err
839+
'
840+
833841
test_expect_success 'overridden default main branch name (env)' '
834842
test_config_global init.defaultBranch nmb &&
835843
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=env git init main-branch-env &&

0 commit comments

Comments
 (0)