Git fork

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 <jltobler@gmail.com>
Acked-by: Phillip Wood <phillip.wood@dunelm.org.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

authored by

Justin Tobler and committed by
Junio C Hamano
ec0f362e c039a46e

+12 -1
+1
advice.c
··· 51 51 [ADVICE_AM_WORK_DIR] = { "amWorkDir" }, 52 52 [ADVICE_CHECKOUT_AMBIGUOUS_REMOTE_BRANCH_NAME] = { "checkoutAmbiguousRemoteBranchName" }, 53 53 [ADVICE_COMMIT_BEFORE_MERGE] = { "commitBeforeMerge" }, 54 + [ADVICE_DEFAULT_BRANCH_NAME] = { "defaultBranchName" }, 54 55 [ADVICE_DETACHED_HEAD] = { "detachedHead" }, 55 56 [ADVICE_DIVERGING] = { "diverging" }, 56 57 [ADVICE_FETCH_SET_HEAD_WARN] = { "fetchRemoteHEADWarn" },
+1
advice.h
··· 18 18 ADVICE_AM_WORK_DIR, 19 19 ADVICE_CHECKOUT_AMBIGUOUS_REMOTE_BRANCH_NAME, 20 20 ADVICE_COMMIT_BEFORE_MERGE, 21 + ADVICE_DEFAULT_BRANCH_NAME, 21 22 ADVICE_DETACHED_HEAD, 22 23 ADVICE_DIVERGING, 23 24 ADVICE_FETCH_SET_HEAD_WARN,
+2 -1
refs.c
··· 664 664 if (!ret) { 665 665 ret = xstrdup("master"); 666 666 if (!quiet) 667 - advise(_(default_branch_name_advice), ret); 667 + advise_if_enabled(ADVICE_DEFAULT_BRANCH_NAME, 668 + _(default_branch_name_advice), ret); 668 669 } 669 670 670 671 full_ref = xstrfmt("refs/heads/%s", ret);
+8
t/t0001-init.sh
··· 830 830 test_grep "<YELLOW>hint: " decoded 831 831 ' 832 832 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 + 833 841 test_expect_success 'overridden default main branch name (env)' ' 834 842 test_config_global init.defaultBranch nmb && 835 843 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=env git init main-branch-env &&