git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Phillip Wood <phillip.wood123@gmail.com>
To: Justin Tobler <jltobler@gmail.com>, git@vger.kernel.org
Cc: ps@pks.im, alan@norbauer.com
Subject: Re: [PATCH v2 3/3] advice: allow disabling default branch name advice
Date: Mon, 24 Mar 2025 09:32:24 +0000	[thread overview]
Message-ID: <16a8af3d-151b-489d-a693-3cd2658c45ef@gmail.com> (raw)
In-Reply-To: <20250321231639.180762-4-jltobler@gmail.com>

Hi Justin

On 21/03/2025 23:16, Justin Tobler wrote:
> 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

> 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 &&


  reply	other threads:[~2025-03-24  9:32 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-19  9:53 bug: git shows hints that should be suppressed alan
2025-03-19  9:58 ` alan
2025-03-19 14:45 ` Elijah Newren
2025-03-20  1:36   ` Justin Tobler
2025-03-20  1:46     ` [PATCH 0/2] clone: suppress unexpected advice message during clone Justin Tobler
2025-03-20  1:46       ` [PATCH 1/2] remote: allow `guess_remote_head()` to suppress advice Justin Tobler
2025-03-20  5:13         ` Patrick Steinhardt
2025-03-20 23:30           ` Justin Tobler
2025-03-21  8:52           ` Junio C Hamano
2025-03-20  1:46       ` [PATCH 2/2] clone: suppress unexpected default branch advice Justin Tobler
2025-03-20  5:13         ` Patrick Steinhardt
2025-03-20 23:36           ` Justin Tobler
2025-03-20 11:10       ` [PATCH 0/2] clone: suppress unexpected advice message during clone Phillip Wood
2025-03-20 23:48         ` Justin Tobler
2025-03-21 16:42           ` Phillip Wood
2025-03-21 23:16       ` [PATCH v2 0/3] " Justin Tobler
2025-03-21 23:16         ` [PATCH v2 1/3] remote: allow `guess_remote_head()` to suppress advice Justin Tobler
2025-03-24  9:31           ` Phillip Wood
2025-03-24 15:21             ` Justin Tobler
2025-03-24 19:29               ` phillip.wood123
2025-03-21 23:16         ` [PATCH v2 2/3] builtin/clone: suppress unexpected default branch advice Justin Tobler
2025-03-24  9:32           ` Phillip Wood
2025-03-24 15:35             ` Justin Tobler
2025-03-21 23:16         ` [PATCH v2 3/3] advice: allow disabling default branch name advice Justin Tobler
2025-03-24  9:32           ` Phillip Wood [this message]
2025-03-23 19:38         ` [PATCH v2 0/3] clone: suppress unexpected advice message during clone Junio C Hamano
2025-03-25  0:51         ` [PATCH v3 " Justin Tobler
2025-03-25  0:51           ` [PATCH v3 1/3] remote: allow `guess_remote_head()` to suppress advice Justin Tobler
2025-03-25  0:51           ` [PATCH v3 2/3] builtin/clone: suppress unexpected default branch advice Justin Tobler
2025-03-25  0:51           ` [PATCH v3 3/3] advice: allow disabling default branch name advice Justin Tobler
2025-03-25 14:35           ` [PATCH v3 0/3] clone: suppress unexpected advice message during clone Phillip Wood
2025-03-20  4:05     ` bug: git shows hints that should be suppressed alan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=16a8af3d-151b-489d-a693-3cd2658c45ef@gmail.com \
    --to=phillip.wood123@gmail.com \
    --cc=alan@norbauer.com \
    --cc=git@vger.kernel.org \
    --cc=jltobler@gmail.com \
    --cc=phillip.wood@dunelm.org.uk \
    --cc=ps@pks.im \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).