git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2 3/3] advice: allow disabling default branch name advice

From
PWPhillip Wood <phillip.wood123@gmail.com>
Date
Mar 24, 2025, 09:32 UTC
Message-ID
<16a8af3d-151b-489d-a693-3cd2658c45ef@gmail.com>
In-Reply-To
<20250321231639.180762-4-jltobler@gmail.com>
Hi Justin
On 21/03/2025 23:16, Justin Tobler wrote:
Show 8 quoted lines
> 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.

Thanks for adding this, it has always bothered me that the only way to silence this hint was by setting a default branch name, rather than being able to just accept git's default by setting the appropiate advice variable. The patch looks good to me

Best Wishes
Phillip
Show 65 quoted lines
> Signed-off-by: Justin Tobler <jltobler@gmail.com>
> ---
>   advice.c        | 1 +
>   advice.h        | 1 +
>   refs.c          | 3 ++-
>   t/t0001-init.sh | 8 ++++++++
>   4 files changed, 12 insertions(+), 1 deletion(-)
> 
> diff --git a/advice.c b/advice.c
> index 1df43b7536..e5f0ff8449 100644
> --- a/advice.c
> +++ b/advice.c
> @@ -51,6 +51,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_DETACHED_HEAD]				= { "detachedHead" },
>   	[ADVICE_DIVERGING]				= { "diverging" },
>   	[ADVICE_FETCH_SET_HEAD_WARN]			= { "fetchRemoteHEADWarn" },
> diff --git a/advice.h b/advice.h
> index d233cfc693..727dcecf4a 100644
> --- a/advice.h
> +++ b/advice.h
> @@ -18,6 +18,7 @@ enum advice_type {
>   	ADVICE_AM_WORK_DIR,
>   	ADVICE_CHECKOUT_AMBIGUOUS_REMOTE_BRANCH_NAME,
>   	ADVICE_COMMIT_BEFORE_MERGE,
> +	ADVICE_DEFAULT_BRANCH_NAME,
>   	ADVICE_DETACHED_HEAD,
>   	ADVICE_DIVERGING,
>   	ADVICE_FETCH_SET_HEAD_WARN,
> diff --git a/refs.c b/refs.c
> index 118465271d..bf9a40d6af 100644
> --- a/refs.c
> +++ b/refs.c
> @@ -664,7 +664,8 @@ char *repo_default_branch_name(struct repository *r, int quiet)
>   	if (!ret) {
>   		ret = xstrdup("master");
>   		if (!quiet)
> -			advise(_(default_branch_name_advice), ret);
> +			advise_if_enabled(ADVICE_DEFAULT_BRANCH_NAME,
> +					  _(default_branch_name_advice), ret);
>   	}
>   
>   	full_ref = xstrfmt("refs/heads/%s", ret);
> diff --git a/t/t0001-init.sh b/t/t0001-init.sh
> index c49d9e0d38..f11a40811f 100755
> --- a/t/t0001-init.sh
> +++ b/t/t0001-init.sh
> @@ -830,6 +830,14 @@ test_expect_success 'advice on unconfigured init.defaultBranch' '
>   	test_grep "<YELLOW>hint: " decoded
>   '
>   
> +test_expect_success 'advice on unconfigured init.defaultBranch disabled' '
> +	test_when_finished "rm -rf no-advice" &&
> +
> +	GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \
> +		git -c advice.defaultBranchName=false init no-advice 2>err &&
> +	test_grep ! "hint: " err
> +'
> +
>   test_expect_success 'overridden default main branch name (env)' '
>   	test_config_global init.defaultBranch nmb &&
>   	GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=env git init main-branch-env &&
Previous: Justin ToblerNext: Junio C Hamano
Message 25 of 32 in “bug: git shows hints that should be suppressed”
  1. alan@norbauer.comMar 19, 2025
  2. alan@norbauer.comMar 19, 2025
  3. Elijah NewrenMar 19, 2025
  4. Justin ToblerMar 20, 2025
  5. 0/2 clone: suppress unexpected advice message during cloneJustin Tobler, Mar 20, 2025
  6. 1/2 remote: allow `guess_remote_head()` to suppress adviceJustin Tobler, Mar 20, 2025
  7. Patrick SteinhardtMar 20, 2025
  8. Justin ToblerMar 20, 2025
  9. Junio C HamanoMar 21, 2025
  10. 2/2 clone: suppress unexpected default branch adviceJustin Tobler, Mar 20, 2025
  11. Patrick SteinhardtMar 20, 2025
  12. Justin ToblerMar 20, 2025
  13. Phillip WoodMar 20, 2025
  14. Justin ToblerMar 20, 2025
  15. Phillip WoodMar 21, 2025
  16. 0/3 clone: suppress unexpected advice message during cloneJustin Tobler, Mar 21, 2025
  17. 1/3 remote: allow `guess_remote_head()` to suppress adviceJustin Tobler, Mar 21, 2025
  18. Phillip WoodMar 24, 2025
  19. Justin ToblerMar 24, 2025
  20. phillip.wood123@gmail.comMar 24, 2025
  21. 2/3 builtin/clone: suppress unexpected default branch adviceJustin Tobler, Mar 21, 2025
  22. Phillip WoodMar 24, 2025
  23. Justin ToblerMar 24, 2025
  24. 3/3 advice: allow disabling default branch name adviceJustin Tobler, Mar 21, 2025
  25. Phillip WoodMar 24, 2025
  26. Junio C HamanoMar 23, 2025
  27. 0/3 clone: suppress unexpected advice message during cloneJustin Tobler, Mar 25, 2025
  28. 1/3 remote: allow `guess_remote_head()` to suppress adviceJustin Tobler, Mar 25, 2025
  29. 2/3 builtin/clone: suppress unexpected default branch adviceJustin Tobler, Mar 25, 2025
  30. 3/3 advice: allow disabling default branch name adviceJustin Tobler, Mar 25, 2025
  31. Phillip WoodMar 25, 2025
  32. alan@norbauer.comMar 20, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.