* [PATCH v2 1/3] remote: allow `guess_remote_head()` to suppress advice
2025-03-21 23:16 ` [PATCH v2 0/3] " Justin Tobler
@ 2025-03-21 23:16 ` Justin Tobler
2025-03-24 9:31 ` Phillip Wood
2025-03-21 23:16 ` [PATCH v2 2/3] builtin/clone: suppress unexpected default branch advice Justin Tobler
` (3 subsequent siblings)
4 siblings, 1 reply; 32+ messages in thread
From: Justin Tobler @ 2025-03-21 23:16 UTC (permalink / raw)
To: git; +Cc: ps, phillip.wood123, alan, Justin Tobler
The `repo_default_branch_name()` invoked through `guess_remote_head()`
is configured to always display the default branch advice message.
Adapt `guess_remote_head()` to accept flags and convert the `all`
parameter to a flag. Add the `REMOTE_GUESS_HEAD_QUIET` flag to to enable
suppression of advice messages. Call sites are updated accordingly.
Signed-off-by: Justin Tobler <jltobler@gmail.com>
---
builtin/fetch.c | 2 +-
builtin/remote.c | 2 +-
remote.c | 10 ++++++----
remote.h | 11 +++++++----
4 files changed, 15 insertions(+), 10 deletions(-)
diff --git a/builtin/fetch.c b/builtin/fetch.c
index 95fd0018b9..763314bfcb 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -1638,7 +1638,7 @@ static int set_head(const struct ref *remote_refs, struct remote *remote)
get_fetch_map(remote_refs, &refspec, &fetch_map_tail, 0);
matches = guess_remote_head(find_ref_by_name(remote_refs, "HEAD"),
- fetch_map, 1);
+ fetch_map, REMOTE_GUESS_HEAD_ALL);
for (ref = matches; ref; ref = ref->next) {
string_list_append(&heads, strip_refshead(ref->name));
}
diff --git a/builtin/remote.c b/builtin/remote.c
index 1b7aad8838..d2aeb5ba1f 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -511,7 +511,7 @@ static int get_head_names(const struct ref *remote_refs, struct ref_states *stat
get_fetch_map(remote_refs, &refspec, &fetch_map_tail, 0);
matches = guess_remote_head(find_ref_by_name(remote_refs, "HEAD"),
- fetch_map, 1);
+ fetch_map, REMOTE_GUESS_HEAD_ALL);
for (ref = matches; ref; ref = ref->next)
string_list_append(&states->heads, abbrev_branch(ref->name));
diff --git a/remote.c b/remote.c
index e609cf5c56..1db88beaf3 100644
--- a/remote.c
+++ b/remote.c
@@ -2297,7 +2297,7 @@ struct ref *get_local_heads(void)
struct ref *guess_remote_head(const struct ref *head,
const struct ref *refs,
- int all)
+ unsigned flags)
{
const struct ref *r;
struct ref *list = NULL;
@@ -2315,8 +2315,10 @@ struct ref *guess_remote_head(const struct ref *head,
return copy_ref(find_ref_by_name(refs, head->symref));
/* If a remote branch exists with the default branch name, let's use it. */
- if (!all) {
- char *default_branch = repo_default_branch_name(the_repository, 0);
+ if (!(flags & REMOTE_GUESS_HEAD_ALL)) {
+ char *default_branch =
+ repo_default_branch_name(the_repository,
+ flags & REMOTE_GUESS_HEAD_QUIET);
char *ref = xstrfmt("refs/heads/%s", default_branch);
r = find_ref_by_name(refs, ref);
@@ -2339,7 +2341,7 @@ struct ref *guess_remote_head(const struct ref *head,
oideq(&r->old_oid, &head->old_oid)) {
*tail = copy_ref(r);
tail = &((*tail)->next);
- if (!all)
+ if (!(flags & REMOTE_GUESS_HEAD_ALL))
break;
}
}
diff --git a/remote.h b/remote.h
index 6be5031f64..7e4943ae3a 100644
--- a/remote.h
+++ b/remote.h
@@ -387,15 +387,18 @@ int format_tracking_info(struct branch *branch, struct strbuf *sb,
int show_divergence_advice);
struct ref *get_local_heads(void);
+
/*
* Find refs from a list which are likely to be pointed to by the given HEAD
- * ref. If 'all' is false, returns the most likely ref; otherwise, returns a
- * list of all candidate refs. If no match is found (or 'head' is NULL),
- * returns NULL. All returns are newly allocated and should be freed.
+ * ref. If REMOTE_GUESS_HEAD_ALL is set, return a list of all candidate refs;
+ * otherwise, return the most likely ref. If no match is found (or 'head' is
+ * NULL), returns NULL. All returns are newly allocated and should be freed.
*/
+#define REMOTE_GUESS_HEAD_ALL (1 << 0)
+#define REMOTE_GUESS_HEAD_QUIET (1 << 1)
struct ref *guess_remote_head(const struct ref *head,
const struct ref *refs,
- int all);
+ unsigned flags);
/* Return refs which no longer exist on remote */
struct ref *get_stale_heads(struct refspec *rs, struct ref *fetch_map);
--
2.49.0
^ permalink raw reply related [flat|nested] 32+ messages in thread* Re: [PATCH v2 1/3] remote: allow `guess_remote_head()` to suppress advice
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
0 siblings, 1 reply; 32+ messages in thread
From: Phillip Wood @ 2025-03-24 9:31 UTC (permalink / raw)
To: Justin Tobler, git; +Cc: ps, alan
Hi Justin
On 21/03/2025 23:16, Justin Tobler wrote:
> The `repo_default_branch_name()` invoked through `guess_remote_head()`
> is configured to always display the default branch advice message.
>
> Adapt `guess_remote_head()` to accept flags and convert the `all`
> parameter to a flag.
This makes sense if we want to convert the boolean argument to a flags
argument. However the only callers that do not set `all` when calling
this function are in git clone where we don't want to emit the warning.
It is probably not worth a re-roll but I wonder if we really need to do
this conversion or if we should just hard code guess_remote_head() to be
quiet when it calls repo_default_branch_name()
Best Wishes
Phillip
> Add the `REMOTE_GUESS_HEAD_QUIET` flag to to enable
> suppression of advice messages. Call sites are updated accordingly.
> > Signed-off-by: Justin Tobler <jltobler@gmail.com>
> ---
> builtin/fetch.c | 2 +-
> builtin/remote.c | 2 +-
> remote.c | 10 ++++++----
> remote.h | 11 +++++++----
> 4 files changed, 15 insertions(+), 10 deletions(-)
>
> diff --git a/builtin/fetch.c b/builtin/fetch.c
> index 95fd0018b9..763314bfcb 100644
> --- a/builtin/fetch.c
> +++ b/builtin/fetch.c
> @@ -1638,7 +1638,7 @@ static int set_head(const struct ref *remote_refs, struct remote *remote)
>
> get_fetch_map(remote_refs, &refspec, &fetch_map_tail, 0);
> matches = guess_remote_head(find_ref_by_name(remote_refs, "HEAD"),
> - fetch_map, 1);
> + fetch_map, REMOTE_GUESS_HEAD_ALL);
> for (ref = matches; ref; ref = ref->next) {
> string_list_append(&heads, strip_refshead(ref->name));
> }
> diff --git a/builtin/remote.c b/builtin/remote.c
> index 1b7aad8838..d2aeb5ba1f 100644
> --- a/builtin/remote.c
> +++ b/builtin/remote.c
> @@ -511,7 +511,7 @@ static int get_head_names(const struct ref *remote_refs, struct ref_states *stat
>
> get_fetch_map(remote_refs, &refspec, &fetch_map_tail, 0);
> matches = guess_remote_head(find_ref_by_name(remote_refs, "HEAD"),
> - fetch_map, 1);
> + fetch_map, REMOTE_GUESS_HEAD_ALL);
> for (ref = matches; ref; ref = ref->next)
> string_list_append(&states->heads, abbrev_branch(ref->name));
>
> diff --git a/remote.c b/remote.c
> index e609cf5c56..1db88beaf3 100644
> --- a/remote.c
> +++ b/remote.c
> @@ -2297,7 +2297,7 @@ struct ref *get_local_heads(void)
>
> struct ref *guess_remote_head(const struct ref *head,
> const struct ref *refs,
> - int all)
> + unsigned flags)
> {
> const struct ref *r;
> struct ref *list = NULL;
> @@ -2315,8 +2315,10 @@ struct ref *guess_remote_head(const struct ref *head,
> return copy_ref(find_ref_by_name(refs, head->symref));
>
> /* If a remote branch exists with the default branch name, let's use it. */
> - if (!all) {
> - char *default_branch = repo_default_branch_name(the_repository, 0);
> + if (!(flags & REMOTE_GUESS_HEAD_ALL)) {
> + char *default_branch =
> + repo_default_branch_name(the_repository,
> + flags & REMOTE_GUESS_HEAD_QUIET);
> char *ref = xstrfmt("refs/heads/%s", default_branch);
>
> r = find_ref_by_name(refs, ref);
> @@ -2339,7 +2341,7 @@ struct ref *guess_remote_head(const struct ref *head,
> oideq(&r->old_oid, &head->old_oid)) {
> *tail = copy_ref(r);
> tail = &((*tail)->next);
> - if (!all)
> + if (!(flags & REMOTE_GUESS_HEAD_ALL))
> break;
> }
> }
> diff --git a/remote.h b/remote.h
> index 6be5031f64..7e4943ae3a 100644
> --- a/remote.h
> +++ b/remote.h
> @@ -387,15 +387,18 @@ int format_tracking_info(struct branch *branch, struct strbuf *sb,
> int show_divergence_advice);
>
> struct ref *get_local_heads(void);
> +
> /*
> * Find refs from a list which are likely to be pointed to by the given HEAD
> - * ref. If 'all' is false, returns the most likely ref; otherwise, returns a
> - * list of all candidate refs. If no match is found (or 'head' is NULL),
> - * returns NULL. All returns are newly allocated and should be freed.
> + * ref. If REMOTE_GUESS_HEAD_ALL is set, return a list of all candidate refs;
> + * otherwise, return the most likely ref. If no match is found (or 'head' is
> + * NULL), returns NULL. All returns are newly allocated and should be freed.
> */
> +#define REMOTE_GUESS_HEAD_ALL (1 << 0)
> +#define REMOTE_GUESS_HEAD_QUIET (1 << 1)
> struct ref *guess_remote_head(const struct ref *head,
> const struct ref *refs,
> - int all);
> + unsigned flags);
>
> /* Return refs which no longer exist on remote */
> struct ref *get_stale_heads(struct refspec *rs, struct ref *fetch_map);
^ permalink raw reply [flat|nested] 32+ messages in thread* Re: [PATCH v2 1/3] remote: allow `guess_remote_head()` to suppress advice
2025-03-24 9:31 ` Phillip Wood
@ 2025-03-24 15:21 ` Justin Tobler
2025-03-24 19:29 ` phillip.wood123
0 siblings, 1 reply; 32+ messages in thread
From: Justin Tobler @ 2025-03-24 15:21 UTC (permalink / raw)
To: phillip.wood; +Cc: git, ps, alan
On 25/03/24 09:31AM, Phillip Wood wrote:
> Hi Justin
>
> On 21/03/2025 23:16, Justin Tobler wrote:
> > The `repo_default_branch_name()` invoked through `guess_remote_head()`
> > is configured to always display the default branch advice message.
> >
> > Adapt `guess_remote_head()` to accept flags and convert the `all`
> > parameter to a flag.
>
> This makes sense if we want to convert the boolean argument to a flags
> argument. However the only callers that do not set `all` when calling this
> function are in git clone where we don't want to emit the warning. It is
> probably not worth a re-roll but I wonder if we really need to do this
> conversion or if we should just hard code guess_remote_head() to be quiet
> when it calls repo_default_branch_name()
Good point. We could just rely on the fact that all current
`guess_remote_head()` callers that do not set `all` also do not want the
advice to be printed.
I have a slight preference to keep this as-is and favor the explicit
configuration, but ultimately I don't feel strongly either way. I am
open to change in a followup version though. :)
Thanks,
-Justin
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: [PATCH v2 1/3] remote: allow `guess_remote_head()` to suppress advice
2025-03-24 15:21 ` Justin Tobler
@ 2025-03-24 19:29 ` phillip.wood123
0 siblings, 0 replies; 32+ messages in thread
From: phillip.wood123 @ 2025-03-24 19:29 UTC (permalink / raw)
To: Justin Tobler, phillip.wood; +Cc: git, ps, alan
Hi Justin
On 24/03/2025 15:21, Justin Tobler wrote:
> On 25/03/24 09:31AM, Phillip Wood wrote:
>> On 21/03/2025 23:16, Justin Tobler wrote:
>>> The `repo_default_branch_name()` invoked through `guess_remote_head()`
>>> is configured to always display the default branch advice message.
>>>
>>> Adapt `guess_remote_head()` to accept flags and convert the `all`
>>> parameter to a flag.
>>
>> This makes sense if we want to convert the boolean argument to a flags
>> argument. However the only callers that do not set `all` when calling this
>> function are in git clone where we don't want to emit the warning. It is
>> probably not worth a re-roll but I wonder if we really need to do this
>> conversion or if we should just hard code guess_remote_head() to be quiet
>> when it calls repo_default_branch_name()
>
> Good point. We could just rely on the fact that all current
> `guess_remote_head()` callers that do not set `all` also do not want the
> advice to be printed.
>
> I have a slight preference to keep this as-is and favor the explicit
> configuration, but ultimately I don't feel strongly either way. I am
> open to change in a followup version though. :)
I'm fine either way so lets keep it as-is if you want
Thanks
Phillip
^ permalink raw reply [flat|nested] 32+ messages in thread
* [PATCH v2 2/3] builtin/clone: suppress unexpected default branch advice
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-21 23:16 ` Justin Tobler
2025-03-24 9:32 ` Phillip Wood
2025-03-21 23:16 ` [PATCH v2 3/3] advice: allow disabling default branch name advice Justin Tobler
` (2 subsequent siblings)
4 siblings, 1 reply; 32+ messages in thread
From: Justin Tobler @ 2025-03-21 23:16 UTC (permalink / raw)
To: git; +Cc: ps, phillip.wood123, alan, Justin Tobler
In 199f44cb2ead (builtin/clone: allow remote helpers to detect repo,
2024-02-27), clones started partially initializing the refdb before
executing the remote helpers by creating a HEAD file and "refs/"
directory. This has resulted in some scenarios where git-clone(1) now
prints the default branch name advice message where it previously did
not.
A side-effect of the HEAD file already existing, is that computation of
the default branch name is handled later in execution. This matters
because prior to 97abaab5f6 (refs: drop `git_default_branch_name()`,
2024-05-17), the default branch value would be computed during its first
execution and cached. Subsequent invocations would simply return the
cached value. Since the next `git_default_branch_name()` call site,
which is invoked through `guess_remote_head()`, is not configured to
suppress the advice message, computing the default branch name results
in the advice message being printed.
Configure `guess_remote_head()` to suppress the advice message,
restoring the previous behavior.
Signed-off-by: Justin Tobler <jltobler@gmail.com>
---
builtin/clone.c | 3 ++-
t/t5607-clone-bundle.sh | 12 ++++++++++++
2 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/builtin/clone.c b/builtin/clone.c
index f14229abf4..a4008715ec 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -1523,7 +1523,8 @@ int cmd_clone(int argc,
}
remote_head = find_ref_by_name(refs, "HEAD");
- remote_head_points_at = guess_remote_head(remote_head, mapped_refs, 0);
+ remote_head_points_at = guess_remote_head(remote_head, mapped_refs,
+ REMOTE_GUESS_HEAD_QUIET);
if (option_branch) {
our_head_points_at = find_remote_branch(mapped_refs, option_branch);
diff --git a/t/t5607-clone-bundle.sh b/t/t5607-clone-bundle.sh
index 82e3621ec5..f526bb1c69 100755
--- a/t/t5607-clone-bundle.sh
+++ b/t/t5607-clone-bundle.sh
@@ -211,4 +211,16 @@ test_expect_success 'git bundle v3 rejects unknown capabilities' '
test_grep "unknown capability .unknown=silly." output
'
+test_expect_success 'cloning bundle suppresses default branch name advice' '
+ test_when_finished "rm -rf bundle-repo clone-repo" &&
+
+ git init bundle-repo &&
+ git -C bundle-repo commit --allow-empty -m init &&
+ git -C bundle-repo bundle create repo.bundle --all &&
+ GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \
+ git clone bundle-repo/repo.bundle clone-repo 2>err &&
+
+ test_grep ! "hint: " err
+'
+
test_done
--
2.49.0
^ permalink raw reply related [flat|nested] 32+ messages in thread* Re: [PATCH v2 2/3] builtin/clone: suppress unexpected default branch advice
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
0 siblings, 1 reply; 32+ messages in thread
From: Phillip Wood @ 2025-03-24 9:32 UTC (permalink / raw)
To: Justin Tobler, git; +Cc: ps, alan
Hi Justin
On 21/03/2025 23:16, Justin Tobler wrote:
> In 199f44cb2ead (builtin/clone: allow remote helpers to detect repo,
> 2024-02-27), clones started partially initializing the refdb before
> executing the remote helpers by creating a HEAD file and "refs/"
> directory. This has resulted in some scenarios where git-clone(1) now
> prints the default branch name advice message where it previously did
> not.
>
> A side-effect of the HEAD file already existing, is that computation of
> the default branch name is handled later in execution. This matters
> because prior to 97abaab5f6 (refs: drop `git_default_branch_name()`,
> 2024-05-17), the default branch value would be computed during its first
> execution and cached. Subsequent invocations would simply return the
> cached value. Since the next `git_default_branch_name()` call site,
> which is invoked through `guess_remote_head()`, is not configured to
> suppress the advice message, computing the default branch name results
> in the advice message being printed.
>
> Configure `guess_remote_head()` to suppress the advice message,
> restoring the previous behavior.
>
> Signed-off-by: Justin Tobler <jltobler@gmail.com>
> ---
> builtin/clone.c | 3 ++-
> t/t5607-clone-bundle.sh | 12 ++++++++++++
> 2 files changed, 14 insertions(+), 1 deletion(-)
>
> diff --git a/builtin/clone.c b/builtin/clone.c
> index f14229abf4..a4008715ec 100644
> --- a/builtin/clone.c
> +++ b/builtin/clone.c
> @@ -1523,7 +1523,8 @@ int cmd_clone(int argc,
> }
>
> remote_head = find_ref_by_name(refs, "HEAD");
> - remote_head_points_at = guess_remote_head(remote_head, mapped_refs, 0);
> + remote_head_points_at = guess_remote_head(remote_head, mapped_refs,
> + REMOTE_GUESS_HEAD_QUIET);
There is another caller of guess_remote_head() in wanted_peer_refs()
which I think we probably want to be quiet as well. I don't see how it
is helpful to the user to prompt them about setting the default branch
name used when creating local repositories during a clone of a remote
repository.
Best Wishes
Phillip
>
> if (option_branch) {
> our_head_points_at = find_remote_branch(mapped_refs, option_branch);
> diff --git a/t/t5607-clone-bundle.sh b/t/t5607-clone-bundle.sh
> index 82e3621ec5..f526bb1c69 100755
> --- a/t/t5607-clone-bundle.sh
> +++ b/t/t5607-clone-bundle.sh
> @@ -211,4 +211,16 @@ test_expect_success 'git bundle v3 rejects unknown capabilities' '
> test_grep "unknown capability .unknown=silly." output
> '
>
> +test_expect_success 'cloning bundle suppresses default branch name advice' '
> + test_when_finished "rm -rf bundle-repo clone-repo" &&
> +
> + git init bundle-repo &&
> + git -C bundle-repo commit --allow-empty -m init &&
> + git -C bundle-repo bundle create repo.bundle --all &&
> + GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \
> + git clone bundle-repo/repo.bundle clone-repo 2>err &&
> +
> + test_grep ! "hint: " err
> +'
> +
> test_done
^ permalink raw reply [flat|nested] 32+ messages in thread* Re: [PATCH v2 2/3] builtin/clone: suppress unexpected default branch advice
2025-03-24 9:32 ` Phillip Wood
@ 2025-03-24 15:35 ` Justin Tobler
0 siblings, 0 replies; 32+ messages in thread
From: Justin Tobler @ 2025-03-24 15:35 UTC (permalink / raw)
To: phillip.wood; +Cc: git, ps, alan
On 25/03/24 09:32AM, Phillip Wood wrote:
> Hi Justin
>
> On 21/03/2025 23:16, Justin Tobler wrote:
> > In 199f44cb2ead (builtin/clone: allow remote helpers to detect repo,
> > 2024-02-27), clones started partially initializing the refdb before
> > executing the remote helpers by creating a HEAD file and "refs/"
> > directory. This has resulted in some scenarios where git-clone(1) now
> > prints the default branch name advice message where it previously did
> > not.
> >
> > A side-effect of the HEAD file already existing, is that computation of
> > the default branch name is handled later in execution. This matters
> > because prior to 97abaab5f6 (refs: drop `git_default_branch_name()`,
> > 2024-05-17), the default branch value would be computed during its first
> > execution and cached. Subsequent invocations would simply return the
> > cached value. Since the next `git_default_branch_name()` call site,
> > which is invoked through `guess_remote_head()`, is not configured to
> > suppress the advice message, computing the default branch name results
> > in the advice message being printed.
> >
> > Configure `guess_remote_head()` to suppress the advice message,
> > restoring the previous behavior.
> >
> > Signed-off-by: Justin Tobler <jltobler@gmail.com>
> > ---
> > builtin/clone.c | 3 ++-
> > t/t5607-clone-bundle.sh | 12 ++++++++++++
> > 2 files changed, 14 insertions(+), 1 deletion(-)
> >
> > diff --git a/builtin/clone.c b/builtin/clone.c
> > index f14229abf4..a4008715ec 100644
> > --- a/builtin/clone.c
> > +++ b/builtin/clone.c
> > @@ -1523,7 +1523,8 @@ int cmd_clone(int argc,
> > }
> > remote_head = find_ref_by_name(refs, "HEAD");
> > - remote_head_points_at = guess_remote_head(remote_head, mapped_refs, 0);
> > + remote_head_points_at = guess_remote_head(remote_head, mapped_refs,
> > + REMOTE_GUESS_HEAD_QUIET);
>
> There is another caller of guess_remote_head() in wanted_peer_refs() which I
> think we probably want to be quiet as well. I don't see how it is helpful to
> the user to prompt them about setting the default branch name used when
> creating local repositories during a clone of a remote repository.
For `wanted_peer_refs()` to invoke `guess_remote_head()`, the
`--single-branch` option must be set. This means, outside of the bundle
clone example, there is another way to get unexpected advice message to
print. Interestingly, if you perform a bundle clone with the
`--single-branch` option, the same advice message prints twice.
I'll send a followup version that also suppresses the unwanted advice
message from `wanted_peer_refs()`.
Thanks,
-Justin
^ permalink raw reply [flat|nested] 32+ messages in thread
* [PATCH v2 3/3] advice: allow disabling default branch name advice
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-21 23:16 ` [PATCH v2 2/3] builtin/clone: suppress unexpected default branch advice Justin Tobler
@ 2025-03-21 23:16 ` Justin Tobler
2025-03-24 9:32 ` Phillip Wood
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
4 siblings, 1 reply; 32+ messages in thread
From: Justin Tobler @ 2025-03-21 23:16 UTC (permalink / raw)
To: git; +Cc: ps, phillip.wood123, alan, Justin Tobler
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>
---
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 &&
--
2.49.0
^ permalink raw reply related [flat|nested] 32+ messages in thread* Re: [PATCH v2 3/3] advice: allow disabling default branch name advice
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
0 siblings, 0 replies; 32+ messages in thread
From: Phillip Wood @ 2025-03-24 9:32 UTC (permalink / raw)
To: Justin Tobler, git; +Cc: ps, alan
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 &&
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: [PATCH v2 0/3] clone: suppress unexpected advice message during clone
2025-03-21 23:16 ` [PATCH v2 0/3] " Justin Tobler
` (2 preceding siblings ...)
2025-03-21 23:16 ` [PATCH v2 3/3] advice: allow disabling default branch name advice Justin Tobler
@ 2025-03-23 19:38 ` Junio C Hamano
2025-03-25 0:51 ` [PATCH v3 " Justin Tobler
4 siblings, 0 replies; 32+ messages in thread
From: Junio C Hamano @ 2025-03-23 19:38 UTC (permalink / raw)
To: Justin Tobler; +Cc: git, ps, phillip.wood123, alan
Justin Tobler <jltobler@gmail.com> writes:
> It has been reported[1] that starting in Git v2.45.0, cloning from a bundle
> results in the default branch name advice message always being displayed
> when it was previously not. It can be reproduced by the following:
>
> git init bundle-repo &&
> git -C bundle-repo --allow-empty -m init &&
Presumably this is "commit --allow-empty -m init" in the bundle-repo
repository?
> git -C bundle-repo bundle create ../repo.bundle --all &&
> git clone repo.bundle bundle-clone
>
> This issue bisects to 199f44cb2ead (builtin/clone: allow remote helpers
> ...
> This series addresses the issue by adapting `guess_remote_head()` to
> support configuring the underlying `git_default_branch_name()`, which
> has since been renamed to `repo_default_branch_name()`, to be quiet and
> suppress the advice message.
Nicely analyzed and described.
> Changes since V1:
>
> - Instead of adding an additional boolean to
> `guess_remote_head()` to suppress the advice message, the
> function is adapted to accepts flags that accoplish the same
> thing.
>
> - Added a test to validate that the advice message is not being
> printed.
>
> - While we are here, added another patch to allow the default
> branch name advice message to be suppressrd by the
> `--no-advice` option.
>
> Thanks,
> -Justin
>
> [1]: <7EC98E2F-144D-4974-94F6-FC24B443651D@norbauer.com>
>
> Justin Tobler (3):
> remote: allow `guess_remote_head()` to suppress advice
> builtin/clone: suppress unexpected default branch advice
> advice: allow disabling default branch name advice
>
> advice.c | 1 +
> advice.h | 1 +
> builtin/clone.c | 3 ++-
> builtin/fetch.c | 2 +-
> builtin/remote.c | 2 +-
> refs.c | 3 ++-
> remote.c | 10 ++++++----
> remote.h | 11 +++++++----
> t/t0001-init.sh | 8 ++++++++
> t/t5607-clone-bundle.sh | 12 ++++++++++++
> 10 files changed, 41 insertions(+), 12 deletions(-)
>
>
> base-commit: 683c54c999c301c2cd6f715c411407c413b1d84e
^ permalink raw reply [flat|nested] 32+ messages in thread* [PATCH v3 0/3] clone: suppress unexpected advice message during clone
2025-03-21 23:16 ` [PATCH v2 0/3] " Justin Tobler
` (3 preceding siblings ...)
2025-03-23 19:38 ` [PATCH v2 0/3] clone: suppress unexpected advice message during clone Junio C Hamano
@ 2025-03-25 0:51 ` Justin Tobler
2025-03-25 0:51 ` [PATCH v3 1/3] remote: allow `guess_remote_head()` to suppress advice Justin Tobler
` (3 more replies)
4 siblings, 4 replies; 32+ messages in thread
From: Justin Tobler @ 2025-03-25 0:51 UTC (permalink / raw)
To: git; +Cc: ps, phillip.wood123, alan, Justin Tobler
It has been reported[1] that starting in Git v2.45.0, cloning from a bundle
results in the default branch name advice message always being displayed
when it was previously not. It can be reproduced by the following:
git init bundle-repo &&
git -C bundle-repo commit --allow-empty -m init &&
git -C bundle-repo bundle create ../repo.bundle --all &&
git clone repo.bundle bundle-clone
This issue bisects to 199f44cb2ead (builtin/clone: allow remote helpers
to detect repo, 2024-02-27) where the refdb is partially initialized
during clones before remote helpers are executed. This partial
initialization creates the HEAD file and "refs/" directory.
A side-effect of this change is that the location of the first
`git_default_branch_name()` gets deferred to a later point of execution.
This matters because `git_default_branch_name()` only computes the
default branch name once and returns a cached value for subsequent
invocations. After this change, the `git_default_branch_name()` call
site that actually computes the value becomes `guess_remote_head()` and
is configured to always show the advice message.
Also, `guess_remote_head()` only invokes `git_default_branch_name()` in
cases where the transport is unable to figure out the remote HEAD and
must guess. This explains why the advice message gets printed for bundle
clones, but not all clones.
This series addresses the issue by adapting `guess_remote_head()` to
support configuring the underlying `git_default_branch_name()`, which
has since been renamed to `repo_default_branch_name()`, to be quiet and
suppress the advice message.
Changes since V2:
- The default branch name advice message may also print with the
`--single-branch` option in certain scenarios. This instance
is also suppressed by setting the `REMOTE_GUESS_HEAD_QUIET`
flag for another `guess_remote_head()` call site invoked
during clones.
Changes since V1:
- Instead of adding an additional boolean to
`guess_remote_head()` to suppress the advice message, the
function is adapted to accepts flags that accoplish the same
thing.
- Added a test to validate that the advice message is not being
printed.
- While we are here, added another patch to allow the default
branch name advice message to be suppressrd by the
`--no-advice` option.
Thanks,
-Justin
[1]: <7EC98E2F-144D-4974-94F6-FC24B443651D@norbauer.com>
Justin Tobler (3):
remote: allow `guess_remote_head()` to suppress advice
builtin/clone: suppress unexpected default branch advice
advice: allow disabling default branch name advice
advice.c | 1 +
advice.h | 1 +
builtin/clone.c | 7 +++++--
builtin/fetch.c | 2 +-
builtin/remote.c | 2 +-
refs.c | 3 ++-
remote.c | 10 ++++++----
remote.h | 11 +++++++----
t/t0001-init.sh | 8 ++++++++
t/t5607-clone-bundle.sh | 12 ++++++++++++
10 files changed, 44 insertions(+), 13 deletions(-)
Range-diff against v2:
1: 4dae06d2dd = 1: 4dae06d2dd remote: allow `guess_remote_head()` to suppress advice
2: 1180caabf1 ! 2: 2a69b881c4 builtin/clone: suppress unexpected default branch advice
@@ Commit message
Signed-off-by: Justin Tobler <jltobler@gmail.com>
## builtin/clone.c ##
+@@ builtin/clone.c: static struct ref *wanted_peer_refs(struct clone_opts *opts,
+ if (head)
+ tail_link_ref(head, &tail);
+ if (option_single_branch)
+- refs = to_free = guess_remote_head(head, refs, 0);
++ refs = to_free =
++ guess_remote_head(head, refs,
++ REMOTE_GUESS_HEAD_QUIET);
+ } else if (option_single_branch) {
+ local_refs = NULL;
+ tail = &local_refs;
@@ builtin/clone.c: int cmd_clone(int argc,
}
@@ t/t5607-clone-bundle.sh: test_expect_success 'git bundle v3 rejects unknown capa
+ git -C bundle-repo commit --allow-empty -m init &&
+ git -C bundle-repo bundle create repo.bundle --all &&
+ GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \
-+ git clone bundle-repo/repo.bundle clone-repo 2>err &&
++ git clone --single-branch bundle-repo/repo.bundle clone-repo 2>err &&
+
+ test_grep ! "hint: " err
+'
3: 6fef1d070c = 3: 98b32cdc99 advice: allow disabling default branch name advice
base-commit: 683c54c999c301c2cd6f715c411407c413b1d84e
--
2.49.0
^ permalink raw reply [flat|nested] 32+ messages in thread* [PATCH v3 1/3] remote: allow `guess_remote_head()` to suppress advice
2025-03-25 0:51 ` [PATCH v3 " Justin Tobler
@ 2025-03-25 0:51 ` Justin Tobler
2025-03-25 0:51 ` [PATCH v3 2/3] builtin/clone: suppress unexpected default branch advice Justin Tobler
` (2 subsequent siblings)
3 siblings, 0 replies; 32+ messages in thread
From: Justin Tobler @ 2025-03-25 0:51 UTC (permalink / raw)
To: git; +Cc: ps, phillip.wood123, alan, Justin Tobler
The `repo_default_branch_name()` invoked through `guess_remote_head()`
is configured to always display the default branch advice message.
Adapt `guess_remote_head()` to accept flags and convert the `all`
parameter to a flag. Add the `REMOTE_GUESS_HEAD_QUIET` flag to to enable
suppression of advice messages. Call sites are updated accordingly.
Signed-off-by: Justin Tobler <jltobler@gmail.com>
---
builtin/fetch.c | 2 +-
builtin/remote.c | 2 +-
remote.c | 10 ++++++----
remote.h | 11 +++++++----
4 files changed, 15 insertions(+), 10 deletions(-)
diff --git a/builtin/fetch.c b/builtin/fetch.c
index 95fd0018b9..763314bfcb 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -1638,7 +1638,7 @@ static int set_head(const struct ref *remote_refs, struct remote *remote)
get_fetch_map(remote_refs, &refspec, &fetch_map_tail, 0);
matches = guess_remote_head(find_ref_by_name(remote_refs, "HEAD"),
- fetch_map, 1);
+ fetch_map, REMOTE_GUESS_HEAD_ALL);
for (ref = matches; ref; ref = ref->next) {
string_list_append(&heads, strip_refshead(ref->name));
}
diff --git a/builtin/remote.c b/builtin/remote.c
index 1b7aad8838..d2aeb5ba1f 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -511,7 +511,7 @@ static int get_head_names(const struct ref *remote_refs, struct ref_states *stat
get_fetch_map(remote_refs, &refspec, &fetch_map_tail, 0);
matches = guess_remote_head(find_ref_by_name(remote_refs, "HEAD"),
- fetch_map, 1);
+ fetch_map, REMOTE_GUESS_HEAD_ALL);
for (ref = matches; ref; ref = ref->next)
string_list_append(&states->heads, abbrev_branch(ref->name));
diff --git a/remote.c b/remote.c
index e609cf5c56..1db88beaf3 100644
--- a/remote.c
+++ b/remote.c
@@ -2297,7 +2297,7 @@ struct ref *get_local_heads(void)
struct ref *guess_remote_head(const struct ref *head,
const struct ref *refs,
- int all)
+ unsigned flags)
{
const struct ref *r;
struct ref *list = NULL;
@@ -2315,8 +2315,10 @@ struct ref *guess_remote_head(const struct ref *head,
return copy_ref(find_ref_by_name(refs, head->symref));
/* If a remote branch exists with the default branch name, let's use it. */
- if (!all) {
- char *default_branch = repo_default_branch_name(the_repository, 0);
+ if (!(flags & REMOTE_GUESS_HEAD_ALL)) {
+ char *default_branch =
+ repo_default_branch_name(the_repository,
+ flags & REMOTE_GUESS_HEAD_QUIET);
char *ref = xstrfmt("refs/heads/%s", default_branch);
r = find_ref_by_name(refs, ref);
@@ -2339,7 +2341,7 @@ struct ref *guess_remote_head(const struct ref *head,
oideq(&r->old_oid, &head->old_oid)) {
*tail = copy_ref(r);
tail = &((*tail)->next);
- if (!all)
+ if (!(flags & REMOTE_GUESS_HEAD_ALL))
break;
}
}
diff --git a/remote.h b/remote.h
index 6be5031f64..7e4943ae3a 100644
--- a/remote.h
+++ b/remote.h
@@ -387,15 +387,18 @@ int format_tracking_info(struct branch *branch, struct strbuf *sb,
int show_divergence_advice);
struct ref *get_local_heads(void);
+
/*
* Find refs from a list which are likely to be pointed to by the given HEAD
- * ref. If 'all' is false, returns the most likely ref; otherwise, returns a
- * list of all candidate refs. If no match is found (or 'head' is NULL),
- * returns NULL. All returns are newly allocated and should be freed.
+ * ref. If REMOTE_GUESS_HEAD_ALL is set, return a list of all candidate refs;
+ * otherwise, return the most likely ref. If no match is found (or 'head' is
+ * NULL), returns NULL. All returns are newly allocated and should be freed.
*/
+#define REMOTE_GUESS_HEAD_ALL (1 << 0)
+#define REMOTE_GUESS_HEAD_QUIET (1 << 1)
struct ref *guess_remote_head(const struct ref *head,
const struct ref *refs,
- int all);
+ unsigned flags);
/* Return refs which no longer exist on remote */
struct ref *get_stale_heads(struct refspec *rs, struct ref *fetch_map);
--
2.49.0
^ permalink raw reply related [flat|nested] 32+ messages in thread* [PATCH v3 2/3] builtin/clone: suppress unexpected default branch advice
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 ` 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
3 siblings, 0 replies; 32+ messages in thread
From: Justin Tobler @ 2025-03-25 0:51 UTC (permalink / raw)
To: git; +Cc: ps, phillip.wood123, alan, Justin Tobler
In 199f44cb2ead (builtin/clone: allow remote helpers to detect repo,
2024-02-27), clones started partially initializing the refdb before
executing the remote helpers by creating a HEAD file and "refs/"
directory. This has resulted in some scenarios where git-clone(1) now
prints the default branch name advice message where it previously did
not.
A side-effect of the HEAD file already existing, is that computation of
the default branch name is handled later in execution. This matters
because prior to 97abaab5f6 (refs: drop `git_default_branch_name()`,
2024-05-17), the default branch value would be computed during its first
execution and cached. Subsequent invocations would simply return the
cached value. Since the next `git_default_branch_name()` call site,
which is invoked through `guess_remote_head()`, is not configured to
suppress the advice message, computing the default branch name results
in the advice message being printed.
Configure `guess_remote_head()` to suppress the advice message,
restoring the previous behavior.
Signed-off-by: Justin Tobler <jltobler@gmail.com>
---
builtin/clone.c | 7 +++++--
t/t5607-clone-bundle.sh | 12 ++++++++++++
2 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/builtin/clone.c b/builtin/clone.c
index f14229abf4..baa76f88c3 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -450,7 +450,9 @@ static struct ref *wanted_peer_refs(struct clone_opts *opts,
if (head)
tail_link_ref(head, &tail);
if (option_single_branch)
- refs = to_free = guess_remote_head(head, refs, 0);
+ refs = to_free =
+ guess_remote_head(head, refs,
+ REMOTE_GUESS_HEAD_QUIET);
} else if (option_single_branch) {
local_refs = NULL;
tail = &local_refs;
@@ -1523,7 +1525,8 @@ int cmd_clone(int argc,
}
remote_head = find_ref_by_name(refs, "HEAD");
- remote_head_points_at = guess_remote_head(remote_head, mapped_refs, 0);
+ remote_head_points_at = guess_remote_head(remote_head, mapped_refs,
+ REMOTE_GUESS_HEAD_QUIET);
if (option_branch) {
our_head_points_at = find_remote_branch(mapped_refs, option_branch);
diff --git a/t/t5607-clone-bundle.sh b/t/t5607-clone-bundle.sh
index 82e3621ec5..d709bea753 100755
--- a/t/t5607-clone-bundle.sh
+++ b/t/t5607-clone-bundle.sh
@@ -211,4 +211,16 @@ test_expect_success 'git bundle v3 rejects unknown capabilities' '
test_grep "unknown capability .unknown=silly." output
'
+test_expect_success 'cloning bundle suppresses default branch name advice' '
+ test_when_finished "rm -rf bundle-repo clone-repo" &&
+
+ git init bundle-repo &&
+ git -C bundle-repo commit --allow-empty -m init &&
+ git -C bundle-repo bundle create repo.bundle --all &&
+ GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \
+ git clone --single-branch bundle-repo/repo.bundle clone-repo 2>err &&
+
+ test_grep ! "hint: " err
+'
+
test_done
--
2.49.0
^ permalink raw reply related [flat|nested] 32+ messages in thread* [PATCH v3 3/3] advice: allow disabling default branch name advice
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 ` Justin Tobler
2025-03-25 14:35 ` [PATCH v3 0/3] clone: suppress unexpected advice message during clone Phillip Wood
3 siblings, 0 replies; 32+ messages in thread
From: Justin Tobler @ 2025-03-25 0:51 UTC (permalink / raw)
To: git; +Cc: ps, phillip.wood123, alan, Justin Tobler
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>
---
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 &&
--
2.49.0
^ permalink raw reply related [flat|nested] 32+ messages in thread* Re: [PATCH v3 0/3] clone: suppress unexpected advice message during clone
2025-03-25 0:51 ` [PATCH v3 " Justin Tobler
` (2 preceding siblings ...)
2025-03-25 0:51 ` [PATCH v3 3/3] advice: allow disabling default branch name advice Justin Tobler
@ 2025-03-25 14:35 ` Phillip Wood
3 siblings, 0 replies; 32+ messages in thread
From: Phillip Wood @ 2025-03-25 14:35 UTC (permalink / raw)
To: Justin Tobler, git; +Cc: ps, alan
Hi Justin
The range-diff below looks good to me, Thanks for working on this
Phillip
On 25/03/2025 00:51, Justin Tobler wrote:
> Range-diff against v2:
> 1: 4dae06d2dd = 1: 4dae06d2dd remote: allow `guess_remote_head()` to suppress advice
> 2: 1180caabf1 ! 2: 2a69b881c4 builtin/clone: suppress unexpected default branch advice
> @@ Commit message
> Signed-off-by: Justin Tobler <jltobler@gmail.com>
>
> ## builtin/clone.c ##
> +@@ builtin/clone.c: static struct ref *wanted_peer_refs(struct clone_opts *opts,
> + if (head)
> + tail_link_ref(head, &tail);
> + if (option_single_branch)
> +- refs = to_free = guess_remote_head(head, refs, 0);
> ++ refs = to_free =
> ++ guess_remote_head(head, refs,
> ++ REMOTE_GUESS_HEAD_QUIET);
> + } else if (option_single_branch) {
> + local_refs = NULL;
> + tail = &local_refs;
> @@ builtin/clone.c: int cmd_clone(int argc,
> }
>
> @@ t/t5607-clone-bundle.sh: test_expect_success 'git bundle v3 rejects unknown capa
> + git -C bundle-repo commit --allow-empty -m init &&
> + git -C bundle-repo bundle create repo.bundle --all &&
> + GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \
> -+ git clone bundle-repo/repo.bundle clone-repo 2>err &&
> ++ git clone --single-branch bundle-repo/repo.bundle clone-repo 2>err &&
> +
> + test_grep ! "hint: " err
> +'
> 3: 6fef1d070c = 3: 98b32cdc99 advice: allow disabling default branch name advice
>
> base-commit: 683c54c999c301c2cd6f715c411407c413b1d84e
^ permalink raw reply [flat|nested] 32+ messages in thread