{"thread":{"id":"63163","subject":"bug: git shows hints that should be suppressed","startedAt":"2025-03-19T09:54:09Z","lastAt":"2025-03-25T14:35:45Z","messageCount":32,"participants":["alan@norbauer.com","Elijah Newren","Justin Tobler","Patrick Steinhardt","Phillip Wood","Junio C Hamano","phillip.wood123@gmail.com"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"514629","messageId":"7EC98E2F-144D-4974-94F6-FC24B443651D@norbauer.com","threadId":"63163","inReplyTo":null,"subject":"bug: git shows hints that should be suppressed","fromName":"","fromEmail":"alan@norbauer.com","sentAt":"2025-03-19T09:53:56Z","receivedAt":"2025-03-19T09:54:09Z","isPatch":false,"sender":{"key":"alan@norbauer.com","avatar":"https://gravatar.com/avatar/686b1635922822f9901ba52712bd696df10573d54b90f30c9390c4e88a7c439b?d=mp&s=160"},"body":"Thank you for filling out a Git bug report!\nPlease answer the following questions to help us understand your issue.\n\nWhat did you do before the bug happened? (Steps to reproduce your issue)\n`GIT_CONFIG_GLOBAL=/dev/null GIT_CONFIG_SYSTEM=/dev/null GIT_CONFIG_NOSYSTEM=0 GIT_ADVICE=0 git clone --quiet /Volumes/sourcecode/npm-packages/packages/repository-tools/node_modules/.cache/@altano/repository-tools/2078b9db1d71a4f4a5422e25a7016c75/git.bundle .`\n\nWhat did you expect to happen? (Expected behavior)\nI would expect the clone to happen without any hints because I provided both `GIT_ADVICE=0` _and_ `--quiet` to the command. Both should suppress the hint.\n\nWhat happened instead? (Actual behavior)\nI received the \"hint: Using 'master' as the name for the initial branch. This default branch name\" on stderr, which caused my tests to fail (I am using git programmatically in a test).\n\nWhat's different between what you expected and what actually happened?\nThe hint on stderr was displayed.\n\nAnything else you want to add:\nThis behavior is NOT observed on git v2.44.0 and is observed on git v2.48.1. So the bug started occurring somewhere in between those versions. I can find the exact version the bug was introduced manually with some effort if that would be helpful.\n\nPlease review the rest of the bug report below.\nYou can delete any lines you don't wish to share.\n\n\n[System Info]\ngit version:\ngit version 2.48.1\ncpu: aarch64\nno commit associated with this build\nsizeof-long: 8\nsizeof-size_t: 8\nshell-path: /nix/store/hmffg6n6ylbl4c30pqc9i71mwqzrd0iv-bash-5.2p37/bin/bash\nfeature: fsmonitor--daemon\nlibcurl: 8.12.1\nOpenSSL: OpenSSL 3.4.1 11 Feb 2025\nzlib: 1.3.1\nuname: Darwin 24.3.0 Darwin Kernel Version 24.3.0: Thu Jan  2 20:24:23 PST 2025; root:xnu-11215.81.4~3/RELEASE_ARM64_T6020 arm64\ncompiler info: clang: 19.1.7 \nlibc info: no libc information available\n$SHELL (typically, interactive shell): /bin/zsh\n\n\n[Enabled Hooks]"},{"id":"514630","messageId":"7AFB2BA3-AFEF-4003-8ADA-0E42D5A3C4BD@norbauer.com","threadId":"63163","inReplyTo":"7EC98E2F-144D-4974-94F6-FC24B443651D@norbauer.com","subject":"Re: bug: git shows hints that should be suppressed","fromName":"","fromEmail":"alan@norbauer.com","sentAt":"2025-03-19T09:58:58Z","receivedAt":"2025-03-19T09:59:12Z","isPatch":false,"sender":{"key":"alan@norbauer.com","avatar":"https://gravatar.com/avatar/686b1635922822f9901ba52712bd696df10573d54b90f30c9390c4e88a7c439b?d=mp&s=160"},"body":"I went ahead and narrowed the range a bit:\n\n✅ 2.44.1 = NO bug\n❌ 2.45.1 = bug reproduces\n\nThanks,\nalan\n\n> On Mar 19, 2025, at 2:53 AM, alan@norbauer.com wrote:\n> \n> Thank you for filling out a Git bug report!\n> Please answer the following questions to help us understand your issue.\n> \n> What did you do before the bug happened? (Steps to reproduce your issue)\n> `GIT_CONFIG_GLOBAL=/dev/null GIT_CONFIG_SYSTEM=/dev/null GIT_CONFIG_NOSYSTEM=0 GIT_ADVICE=0 git clone --quiet /Volumes/sourcecode/npm-packages/packages/repository-tools/node_modules/.cache/@altano/repository-tools/2078b9db1d71a4f4a5422e25a7016c75/git.bundle .`\n> \n> What did you expect to happen? (Expected behavior)\n> I would expect the clone to happen without any hints because I provided both `GIT_ADVICE=0` _and_ `--quiet` to the command. Both should suppress the hint.\n> \n> What happened instead? (Actual behavior)\n> I received the \"hint: Using 'master' as the name for the initial branch. This default branch name\" on stderr, which caused my tests to fail (I am using git programmatically in a test).\n> \n> What's different between what you expected and what actually happened?\n> The hint on stderr was displayed.\n> \n> Anything else you want to add:\n> This behavior is NOT observed on git v2.44.0 and is observed on git v2.48.1. So the bug started occurring somewhere in between those versions. I can find the exact version the bug was introduced manually with some effort if that would be helpful.\n> \n> Please review the rest of the bug report below.\n> You can delete any lines you don't wish to share.\n> \n> \n> [System Info]\n> git version:\n> git version 2.48.1\n> cpu: aarch64\n> no commit associated with this build\n> sizeof-long: 8\n> sizeof-size_t: 8\n> shell-path: /nix/store/hmffg6n6ylbl4c30pqc9i71mwqzrd0iv-bash-5.2p37/bin/bash\n> feature: fsmonitor--daemon\n> libcurl: 8.12.1\n> OpenSSL: OpenSSL 3.4.1 11 Feb 2025\n> zlib: 1.3.1\n> uname: Darwin 24.3.0 Darwin Kernel Version 24.3.0: Thu Jan  2 20:24:23 PST 2025; root:xnu-11215.81.4~3/RELEASE_ARM64_T6020 arm64\n> compiler info: clang: 19.1.7 \n> libc info: no libc information available\n> $SHELL (typically, interactive shell): /bin/zsh\n> \n> \n> [Enabled Hooks]\n\n"},{"id":"514646","messageId":"CABPp-BGTrEfGqX=o3W5rfqZiRdEuAzdKJuT8W0J=6kSY9ME4LQ@mail.gmail.com","threadId":"63163","inReplyTo":"7EC98E2F-144D-4974-94F6-FC24B443651D@norbauer.com","subject":"Re: bug: git shows hints that should be suppressed","fromName":"Elijah Newren","fromEmail":"newren@gmail.com","sentAt":"2025-03-19T14:45:30Z","receivedAt":"2025-03-19T14:45:43Z","isPatch":false,"sender":{"key":"newren@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5455730?v=4"},"body":"On Wed, Mar 19, 2025 at 2:59 AM <alan@norbauer.com> wrote:\n>\n> Thank you for filling out a Git bug report!\n> Please answer the following questions to help us understand your issue.\n>\n> What did you do before the bug happened? (Steps to reproduce your issue)\n> `GIT_CONFIG_GLOBAL=/dev/null GIT_CONFIG_SYSTEM=/dev/null GIT_CONFIG_NOSYSTEM=0 GIT_ADVICE=0 git clone --quiet /Volumes/sourcecode/npm-packages/packages/repository-tools/node_modules/.cache/@altano/repository-tools/2078b9db1d71a4f4a5422e25a7016c75/git.bundle .`\n>\n> What did you expect to happen? (Expected behavior)\n> I would expect the clone to happen without any hints because I provided both `GIT_ADVICE=0` _and_ `--quiet` to the command. Both should suppress the hint.\n>\n> What happened instead? (Actual behavior)\n> I received the \"hint: Using 'master' as the name for the initial branch. This default branch name\" on stderr, which caused my tests to fail (I am using git programmatically in a test).\n>\n> What's different between what you expected and what actually happened?\n> The hint on stderr was displayed.\n>\n> Anything else you want to add:\n> This behavior is NOT observed on git v2.44.0 and is observed on git v2.48.1. So the bug started occurring somewhere in between those versions. I can find the exact version the bug was introduced manually with some effort if that would be helpful.\n\nBisects to 199f44cb2ead (builtin/clone: allow remote helpers to detect\nrepo, 2024-02-27); cc'ing its author.\n"},{"id":"514705","messageId":"fff634dh5qeb4rgjqn7cru7v4a2voj4us4thvwtttxjcdnu2bu@jvv3htcon2ul","threadId":"63163","inReplyTo":"CABPp-BGTrEfGqX=o3W5rfqZiRdEuAzdKJuT8W0J=6kSY9ME4LQ@mail.gmail.com","subject":"Re: bug: git shows hints that should be suppressed","fromName":"Justin Tobler","fromEmail":"jltobler@gmail.com","sentAt":"2025-03-20T01:36:51Z","receivedAt":"2025-03-20T01:40:26Z","isPatch":false,"sender":{"key":"jltobler@gmail.com","avatar":"https://avatars.githubusercontent.com/u/53454972?v=4"},"body":"On 25/03/19 07:45AM, Elijah Newren wrote:\n> On Wed, Mar 19, 2025 at 2:59 AM <alan@norbauer.com> wrote:\n> >\n> > Thank you for filling out a Git bug report!\n> > Please answer the following questions to help us understand your issue.\n> >\n> > What did you do before the bug happened? (Steps to reproduce your issue)\n> > `GIT_CONFIG_GLOBAL=/dev/null GIT_CONFIG_SYSTEM=/dev/null GIT_CONFIG_NOSYSTEM=0 GIT_ADVICE=0 git clone --quiet /Volumes/sourcecode/npm-packages/packages/repository-tools/node_modules/.cache/@altano/repository-tools/2078b9db1d71a4f4a5422e25a7016c75/git.bundle .`\n> >\n> > What did you expect to happen? (Expected behavior)\n> > I would expect the clone to happen without any hints because I provided both `GIT_ADVICE=0` _and_ `--quiet` to the command. Both should suppress the hint.\n> >\n> > What happened instead? (Actual behavior)\n> > I received the \"hint: Using 'master' as the name for the initial branch. This default branch name\" on stderr, which caused my tests to fail (I am using git programmatically in a test).\n> >\n> > What's different between what you expected and what actually happened?\n> > The hint on stderr was displayed.\n> >\n> > Anything else you want to add:\n> > This behavior is NOT observed on git v2.44.0 and is observed on git v2.48.1. So the bug started occurring somewhere in between those versions. I can find the exact version the bug was introduced manually with some effort if that would be helpful.\n> \n> Bisects to 199f44cb2ead (builtin/clone: allow remote helpers to detect\n> repo, 2024-02-27); cc'ing its author.\n\nIt looks like prior to 199f44cb2ead (builtin/clone: allow remote helpers\nto detect repo, 2024-02-27), the default branch name advice message\nwould never be printed when cloning from a bundle regardless of whether\n`--quiet` option was set. This particual advice message also doesn't\nrespect `GIT_ADVICE` either. So something about the change has made the\nmessage start printing when it previously did not.\n\nDigging a bit further, this change started partially initializing the\nrefdb with a HEAD file which had a side-effect of changing the location\nwhere the first `git_default_branch_name()` was invoked. This matters\nbecause `git_default_branch_name()` only computes the default branch\nname once and uses a cached value for subsequent invocations.\n\nPreviously, `create_reference_database()` was the first\n`git_default_branch_name()` call site and was configured to always\nsuppress the advice message. Due to the refdb being partially\ninitialized with a HEAD file, `create_reference_database()` stopped\ninvoking `git_default_branch_name()` altogether and the default branch\nname computation was defferred to a subsequent potential call site\n`guess_remote_head()`. At this location, `git_default_branch_name()` is\nconfigured to not suppress advice messages.\n\nAlso, `guess_remote_head()` only invokes `git_default_branch_name()` in\ncases where the transport is unable to figure out the remote HEAD and\nmust guess. This explains why the advice message gets printed for bundle\nclones, but not all clones.\n\nOne option to fix this would be to adapt `guess_remote_head()` to\nsupport configuring the underlying `git_default_branch_name()`, which\nhas since been renamed to `repo_default_branch_name()`, to be quiet and\nsuppress the advice message. The call site in clone could then be\nupdated accordingly.\n\nI'll submit a patch that does this.\n\n-Justin\n"},{"id":"514706","messageId":"20250320014646.2899791-1-jltobler@gmail.com","threadId":"63163","inReplyTo":"fff634dh5qeb4rgjqn7cru7v4a2voj4us4thvwtttxjcdnu2bu@jvv3htcon2ul","subject":"[PATCH 0/2] clone: suppress unexpected advice message during clone","fromName":"Justin Tobler","fromEmail":"jltobler@gmail.com","sentAt":"2025-03-20T01:46:44Z","receivedAt":"2025-03-20T02:21:47Z","isPatch":true,"sender":{"key":"jltobler@gmail.com","avatar":"https://avatars.githubusercontent.com/u/53454972?v=4"},"body":"It has been reported[1] that starting in Git v2.45.0, cloning from a bundle\nresults in the default branch name advice message always being displayed\nwhen it was previously not. It can be reproduced by the following:\n\n        git init bundle-repo &&\n        git -C bundle-repo --allow-empty -m init &&\n        git -C bundle-repo bundle create ../repo.bundle --all &&\n        git clone bundle.repo bundle-clone\n\nThis issue bisects to 199f44cb2ead (builtin/clone: allow remote helpers\nto detect repo, 2024-02-27) where the refdb is partially initialized\nduring clones before remote helpers are executed. This partial\ninitilization creates the HEAD file and \"refs/\" directory.\n\nA side-effect of this change is that the location of the first\n`git_default_branch_name()` gets deferred to a later point of execution.\nThis matters because `git_default_branch_name()` only computes the\ndefault branch name once and returns a cached value for subsequent\ninvocations. After this change, the `git_default_branch_name()` call\nsite that actually computes the value becomes `guess_remote_head()` and\nis configured to always show the advice message.\n\nAlso, `guess_remote_head()` only invokes `git_default_branch_name()` in\ncases where the transport is unable to figure out the remote HEAD and\nmust guess. This explains why the advice message gets printed for bundle\nclones, but not all clones.\n\nThis series addresses the issue by adapting `guess_remote_head()` to\nsupport configuring the underlying `git_default_branch_name()`, which\nhas since been renamed to `repo_default_branch_name()`, to be quiet and\nsuppress the advice message.\n\nThanks,\n-Justin\n\n[1]: <7EC98E2F-144D-4974-94F6-FC24B443651D@norbauer.com>\n\nJustin Tobler (2):\n  remote: allow `guess_remote_head()` to suppress advice\n  clone: suppress unexpected default branch advice\n\n builtin/clone.c  | 4 ++--\n builtin/fetch.c  | 2 +-\n builtin/remote.c | 2 +-\n remote.c         | 4 ++--\n remote.h         | 2 +-\n 5 files changed, 7 insertions(+), 7 deletions(-)\n\n\nbase-commit: 683c54c999c301c2cd6f715c411407c413b1d84e\n-- \n2.49.0\n\n"},{"id":"514707","messageId":"20250320014646.2899791-2-jltobler@gmail.com","threadId":"63163","inReplyTo":"20250320014646.2899791-1-jltobler@gmail.com","subject":"[PATCH 1/2] remote: allow `guess_remote_head()` to suppress advice","fromName":"Justin Tobler","fromEmail":"jltobler@gmail.com","sentAt":"2025-03-20T01:46:45Z","receivedAt":"2025-03-20T02:21:48Z","isPatch":true,"sender":{"key":"jltobler@gmail.com","avatar":"https://avatars.githubusercontent.com/u/53454972?v=4"},"body":"The `repo_default_branch_name()` invoked through `guess_remote_head()`\nis configured to always display the default branch advice message.\n\nAdd an additional parameter to the `guess_remote_head()` function\nsignature to enable suppression of advice messages and update call sites\naccordingly.\n\nSigned-off-by: Justin Tobler <jltobler@gmail.com>\n---\n builtin/clone.c  | 4 ++--\n builtin/fetch.c  | 2 +-\n builtin/remote.c | 2 +-\n remote.c         | 4 ++--\n remote.h         | 2 +-\n 5 files changed, 7 insertions(+), 7 deletions(-)\n\ndiff --git a/builtin/clone.c b/builtin/clone.c\nindex f14229abf4..9eb66234bc 100644\n--- a/builtin/clone.c\n+++ b/builtin/clone.c\n@@ -450,7 +450,7 @@ static struct ref *wanted_peer_refs(struct clone_opts *opts,\n \t\tif (head)\n \t\t\ttail_link_ref(head, &tail);\n \t\tif (option_single_branch)\n-\t\t\trefs = to_free = guess_remote_head(head, refs, 0);\n+\t\t\trefs = to_free = guess_remote_head(head, refs, 0, 0);\n \t} else if (option_single_branch) {\n \t\tlocal_refs = NULL;\n \t\ttail = &local_refs;\n@@ -1523,7 +1523,7 @@ int cmd_clone(int argc,\n \t}\n \n \tremote_head = find_ref_by_name(refs, \"HEAD\");\n-\tremote_head_points_at = guess_remote_head(remote_head, mapped_refs, 0);\n+\tremote_head_points_at = guess_remote_head(remote_head, mapped_refs, 0, 0);\n \n \tif (option_branch) {\n \t\tour_head_points_at = find_remote_branch(mapped_refs, option_branch);\ndiff --git a/builtin/fetch.c b/builtin/fetch.c\nindex 95fd0018b9..a4f5b3e683 100644\n--- a/builtin/fetch.c\n+++ b/builtin/fetch.c\n@@ -1638,7 +1638,7 @@ static int set_head(const struct ref *remote_refs, struct remote *remote)\n \n \tget_fetch_map(remote_refs, &refspec, &fetch_map_tail, 0);\n \tmatches = guess_remote_head(find_ref_by_name(remote_refs, \"HEAD\"),\n-\t\t\t\t    fetch_map, 1);\n+\t\t\t\t    fetch_map, 1, 0);\n \tfor (ref = matches; ref; ref = ref->next) {\n \t\tstring_list_append(&heads, strip_refshead(ref->name));\n \t}\ndiff --git a/builtin/remote.c b/builtin/remote.c\nindex 1b7aad8838..ebd1a796d2 100644\n--- a/builtin/remote.c\n+++ b/builtin/remote.c\n@@ -511,7 +511,7 @@ static int get_head_names(const struct ref *remote_refs, struct ref_states *stat\n \n \tget_fetch_map(remote_refs, &refspec, &fetch_map_tail, 0);\n \tmatches = guess_remote_head(find_ref_by_name(remote_refs, \"HEAD\"),\n-\t\t\t\t    fetch_map, 1);\n+\t\t\t\t    fetch_map, 1, 0);\n \tfor (ref = matches; ref; ref = ref->next)\n \t\tstring_list_append(&states->heads, abbrev_branch(ref->name));\n \ndiff --git a/remote.c b/remote.c\nindex e609cf5c56..e9e55ecdbf 100644\n--- a/remote.c\n+++ b/remote.c\n@@ -2297,7 +2297,7 @@ struct ref *get_local_heads(void)\n \n struct ref *guess_remote_head(const struct ref *head,\n \t\t\t      const struct ref *refs,\n-\t\t\t      int all)\n+\t\t\t      int all, int quiet)\n {\n \tconst struct ref *r;\n \tstruct ref *list = NULL;\n@@ -2316,7 +2316,7 @@ struct ref *guess_remote_head(const struct ref *head,\n \n \t/* If a remote branch exists with the default branch name, let's use it. */\n \tif (!all) {\n-\t\tchar *default_branch = repo_default_branch_name(the_repository, 0);\n+\t\tchar *default_branch = repo_default_branch_name(the_repository, quiet);\n \t\tchar *ref = xstrfmt(\"refs/heads/%s\", default_branch);\n \n \t\tr = find_ref_by_name(refs, ref);\ndiff --git a/remote.h b/remote.h\nindex 6be5031f64..49c7b644bb 100644\n--- a/remote.h\n+++ b/remote.h\n@@ -395,7 +395,7 @@ struct ref *get_local_heads(void);\n  */\n struct ref *guess_remote_head(const struct ref *head,\n \t\t\t      const struct ref *refs,\n-\t\t\t      int all);\n+\t\t\t      int all, int quiet);\n \n /* Return refs which no longer exist on remote */\n struct ref *get_stale_heads(struct refspec *rs, struct ref *fetch_map);\n-- \n2.49.0\n\n"},{"id":"514708","messageId":"20250320014646.2899791-3-jltobler@gmail.com","threadId":"63163","inReplyTo":"20250320014646.2899791-1-jltobler@gmail.com","subject":"[PATCH 2/2] clone: suppress unexpected default branch advice","fromName":"Justin Tobler","fromEmail":"jltobler@gmail.com","sentAt":"2025-03-20T01:46:46Z","receivedAt":"2025-03-20T02:21:49Z","isPatch":true,"sender":{"key":"jltobler@gmail.com","avatar":"https://avatars.githubusercontent.com/u/53454972?v=4"},"body":"In 199f44cb2ead (builtin/clone: allow remote helpers to detect repo,\n2024-02-27), clones started partially initializing the refdb before\nexecuting the remote helpers by creating a HEAD file and \"refs/\"\ndirectory. This has resulted in some scenarios where git-clone(1) now\nprints the default branch name advice message where it previously did\nnot.\n\nA side-effect of the HEAD file already existing, is that computation of\nthe default branch name is handled later in execution. This matters\nbecause prior to 97abaab5f6 (refs: drop `git_default_branch_name()`,\n2024-05-17), the default branch value would be computed during its first\nexecution and cached. Subsequent invocations would simply return the\ncached value. Since the next `git_default_branch_name()` call site,\nwhich is invoked through `guess_remote_head()`, is not configured to\nsuppress the advice message, computing the default branch name results\nin the advice message being printed.\n\nConfigure `guess_remote_head()` to suppress the advice message,\nrestoring the previous behavior.\n\nSigned-off-by: Justin Tobler <jltobler@gmail.com>\n---\n builtin/clone.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/builtin/clone.c b/builtin/clone.c\nindex 9eb66234bc..3b166b05e3 100644\n--- a/builtin/clone.c\n+++ b/builtin/clone.c\n@@ -1523,7 +1523,7 @@ int cmd_clone(int argc,\n \t}\n \n \tremote_head = find_ref_by_name(refs, \"HEAD\");\n-\tremote_head_points_at = guess_remote_head(remote_head, mapped_refs, 0, 0);\n+\tremote_head_points_at = guess_remote_head(remote_head, mapped_refs, 0, 1);\n \n \tif (option_branch) {\n \t\tour_head_points_at = find_remote_branch(mapped_refs, option_branch);\n-- \n2.49.0\n\n"},{"id":"514711","messageId":"00213714-D232-49BB-BE8F-300E74758E8C@norbauer.com","threadId":"63163","inReplyTo":"fff634dh5qeb4rgjqn7cru7v4a2voj4us4thvwtttxjcdnu2bu@jvv3htcon2ul","subject":"Re: bug: git shows hints that should be suppressed","fromName":"","fromEmail":"alan@norbauer.com","sentAt":"2025-03-20T04:05:07Z","receivedAt":"2025-03-20T04:05:30Z","isPatch":false,"sender":{"key":"alan@norbauer.com","avatar":"https://gravatar.com/avatar/686b1635922822f9901ba52712bd696df10573d54b90f30c9390c4e88a7c439b?d=mp&s=160"},"body":"Thank you, Justin and Elijah. I really appreciate you digging in.\n\n> On Mar 19, 2025, at 6:40 PM, Justin Tobler <jltobler@gmail.com> wrote:\n> \n> ﻿On 25/03/19 07:45AM, Elijah Newren wrote:\n>>> On Wed, Mar 19, 2025 at 2:59 AM <alan@norbauer.com> wrote:\n>>> \n>>> Thank you for filling out a Git bug report!\n>>> Please answer the following questions to help us understand your issue.\n>>> \n>>> What did you do before the bug happened? (Steps to reproduce your issue)\n>>> `GIT_CONFIG_GLOBAL=/dev/null GIT_CONFIG_SYSTEM=/dev/null GIT_CONFIG_NOSYSTEM=0 GIT_ADVICE=0 git clone --quiet /Volumes/sourcecode/npm-packages/packages/repository-tools/node_modules/.cache/@altano/repository-tools/2078b9db1d71a4f4a5422e25a7016c75/git.bundle .`\n>>> \n>>> What did you expect to happen? (Expected behavior)\n>>> I would expect the clone to happen without any hints because I provided both `GIT_ADVICE=0` _and_ `--quiet` to the command. Both should suppress the hint.\n>>> \n>>> What happened instead? (Actual behavior)\n>>> I received the \"hint: Using 'master' as the name for the initial branch. This default branch name\" on stderr, which caused my tests to fail (I am using git programmatically in a test).\n>>> \n>>> What's different between what you expected and what actually happened?\n>>> The hint on stderr was displayed.\n>>> \n>>> Anything else you want to add:\n>>> This behavior is NOT observed on git v2.44.0 and is observed on git v2.48.1. So the bug started occurring somewhere in between those versions. I can find the exact version the bug was introduced manually with some effort if that would be helpful.\n>> \n>> Bisects to 199f44cb2ead (builtin/clone: allow remote helpers to detect\n>> repo, 2024-02-27); cc'ing its author.\n> \n> It looks like prior to 199f44cb2ead (builtin/clone: allow remote helpers\n> to detect repo, 2024-02-27), the default branch name advice message\n> would never be printed when cloning from a bundle regardless of whether\n> `--quiet` option was set. This particual advice message also doesn't\n> respect `GIT_ADVICE` either. So something about the change has made the\n> message start printing when it previously did not.\n> \n> Digging a bit further, this change started partially initializing the\n> refdb with a HEAD file which had a side-effect of changing the location\n> where the first `git_default_branch_name()` was invoked. This matters\n> because `git_default_branch_name()` only computes the default branch\n> name once and uses a cached value for subsequent invocations.\n> \n> Previously, `create_reference_database()` was the first\n> `git_default_branch_name()` call site and was configured to always\n> suppress the advice message. Due to the refdb being partially\n> initialized with a HEAD file, `create_reference_database()` stopped\n> invoking `git_default_branch_name()` altogether and the default branch\n> name computation was defferred to a subsequent potential call site\n> `guess_remote_head()`. At this location, `git_default_branch_name()` is\n> configured to not suppress advice messages.\n> \n> Also, `guess_remote_head()` only invokes `git_default_branch_name()` in\n> cases where the transport is unable to figure out the remote HEAD and\n> must guess. This explains why the advice message gets printed for bundle\n> clones, but not all clones.\n> \n> One option to fix this would be to adapt `guess_remote_head()` to\n> support configuring the underlying `git_default_branch_name()`, which\n> has since been renamed to `repo_default_branch_name()`, to be quiet and\n> suppress the advice message. The call site in clone could then be\n> updated accordingly.\n> \n> I'll submit a patch that does this.\n> \n> -Justin\n"},{"id":"514713","messageId":"Z9ukDuvsLXhYTQAP@pks.im","threadId":"63163","inReplyTo":"20250320014646.2899791-2-jltobler@gmail.com","subject":"Re: [PATCH 1/2] remote: allow `guess_remote_head()` to suppress advice","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2025-03-20T05:13:50Z","receivedAt":"2025-03-20T05:13:56Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Wed, Mar 19, 2025 at 08:46:45PM -0500, Justin Tobler wrote:\n> diff --git a/remote.h b/remote.h\n> index 6be5031f64..49c7b644bb 100644\n> --- a/remote.h\n> +++ b/remote.h\n> @@ -395,7 +395,7 @@ struct ref *get_local_heads(void);\n>   */\n>  struct ref *guess_remote_head(const struct ref *head,\n>  \t\t\t      const struct ref *refs,\n> -\t\t\t      int all);\n> +\t\t\t      int all, int quiet);\n\nI think instead of introducing another boolean parameter it would be\npreferable to have a preparatory commit that turns `all` into `flags`.\n\nPatrick\n"},{"id":"514714","messageId":"Z9ukEUvuiPUQ3eiI@pks.im","threadId":"63163","inReplyTo":"20250320014646.2899791-3-jltobler@gmail.com","subject":"Re: [PATCH 2/2] clone: suppress unexpected default branch advice","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2025-03-20T05:13:53Z","receivedAt":"2025-03-20T05:13:57Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Wed, Mar 19, 2025 at 08:46:46PM -0500, Justin Tobler wrote:\n> diff --git a/builtin/clone.c b/builtin/clone.c\n> index 9eb66234bc..3b166b05e3 100644\n> --- a/builtin/clone.c\n> +++ b/builtin/clone.c\n> @@ -1523,7 +1523,7 @@ int cmd_clone(int argc,\n>  \t}\n>  \n>  \tremote_head = find_ref_by_name(refs, \"HEAD\");\n> -\tremote_head_points_at = guess_remote_head(remote_head, mapped_refs, 0, 0);\n> +\tremote_head_points_at = guess_remote_head(remote_head, mapped_refs, 0, 1);\n>  \n>  \tif (option_branch) {\n>  \t\tour_head_points_at = find_remote_branch(mapped_refs, option_branch);\n\nMakes sense. You don't have control over the branch name anyway when\ncloning, so it's nonsensical to print that advise. Another subsequent\nstep could be to turn the `advise()` into `advise_if_enabled()`, but\nthat change isn't really needed for git-clone(1) because there wouldn't\never be a reason to print it.\n\nDo we want to add a test somewhere that demonstrates that we don't print\nthe advise anymore?\n\nThanks for fixing this!\n\nPatrick\n"},{"id":"514757","messageId":"926210f4-a8ff-4ac2-8b7f-85cd5598d77b@gmail.com","threadId":"63163","inReplyTo":"20250320014646.2899791-1-jltobler@gmail.com","subject":"Re: [PATCH 0/2] clone: suppress unexpected advice message during clone","fromName":"Phillip Wood","fromEmail":"phillip.wood123@gmail.com","sentAt":"2025-03-20T11:10:33Z","receivedAt":"2025-03-20T11:10:36Z","isPatch":true,"sender":{"key":"phillip.wood@dunelm.org.uk","avatar":null},"body":"Hi Justin\n\nOn 20/03/2025 01:46, Justin Tobler wrote:\n> \n> A side-effect of this change is that the location of the first\n> `git_default_branch_name()` gets deferred to a later point of execution.\n> This matters because `git_default_branch_name()` only computes the\n> default branch name once and returns a cached value for subsequent\n> invocations. After this change, the `git_default_branch_name()` call\n> site that actually computes the value becomes `guess_remote_head()` and\n> is configured to always show the advice message.\n\nIsn't the fundamental cause of this bug that advise() ignores \nGIT_ADVICE? I'm not really clear why \"git --no-advice\" only applies to \nadvice that is guarded by advice_enabled() when it is documented as \ndisabling all advice hints.\n\nBest Wishes\n\nPhillip\n"},{"id":"514812","messageId":"rbuwquadvjmqbyhbikmupwd53xt6dpu6rpv6oyso2pscihddzw@eoovi3vqkzud","threadId":"63163","inReplyTo":"Z9ukDuvsLXhYTQAP@pks.im","subject":"Re: [PATCH 1/2] remote: allow `guess_remote_head()` to suppress advice","fromName":"Justin Tobler","fromEmail":"jltobler@gmail.com","sentAt":"2025-03-20T23:30:39Z","receivedAt":"2025-03-20T23:34:15Z","isPatch":true,"sender":{"key":"jltobler@gmail.com","avatar":"https://avatars.githubusercontent.com/u/53454972?v=4"},"body":"On 25/03/20 06:13AM, Patrick Steinhardt wrote:\n> On Wed, Mar 19, 2025 at 08:46:45PM -0500, Justin Tobler wrote:\n> > diff --git a/remote.h b/remote.h\n> > index 6be5031f64..49c7b644bb 100644\n> > --- a/remote.h\n> > +++ b/remote.h\n> > @@ -395,7 +395,7 @@ struct ref *get_local_heads(void);\n> >   */\n> >  struct ref *guess_remote_head(const struct ref *head,\n> >  \t\t\t      const struct ref *refs,\n> > -\t\t\t      int all);\n> > +\t\t\t      int all, int quiet);\n> \n> I think instead of introducing another boolean parameter it would be\n> preferable to have a preparatory commit that turns `all` into `flags`.\n\nThat makes sense. I'll adapt the next version accordingly.\n\nThanks,\n-Justin\n"},{"id":"514813","messageId":"7id72d5g7glcp3xbsvhl4p2tpavs6dfisxhz7xvvdavdnkd5gp@nqznubj7rnbr","threadId":"63163","inReplyTo":"Z9ukEUvuiPUQ3eiI@pks.im","subject":"Re: [PATCH 2/2] clone: suppress unexpected default branch advice","fromName":"Justin Tobler","fromEmail":"jltobler@gmail.com","sentAt":"2025-03-20T23:36:35Z","receivedAt":"2025-03-20T23:40:11Z","isPatch":true,"sender":{"key":"jltobler@gmail.com","avatar":"https://avatars.githubusercontent.com/u/53454972?v=4"},"body":"On 25/03/20 06:13AM, Patrick Steinhardt wrote:\n> On Wed, Mar 19, 2025 at 08:46:46PM -0500, Justin Tobler wrote:\n> > diff --git a/builtin/clone.c b/builtin/clone.c\n> > index 9eb66234bc..3b166b05e3 100644\n> > --- a/builtin/clone.c\n> > +++ b/builtin/clone.c\n> > @@ -1523,7 +1523,7 @@ int cmd_clone(int argc,\n> >  \t}\n> >  \n> >  \tremote_head = find_ref_by_name(refs, \"HEAD\");\n> > -\tremote_head_points_at = guess_remote_head(remote_head, mapped_refs, 0, 0);\n> > +\tremote_head_points_at = guess_remote_head(remote_head, mapped_refs, 0, 1);\n> >  \n> >  \tif (option_branch) {\n> >  \t\tour_head_points_at = find_remote_branch(mapped_refs, option_branch);\n> \n> Makes sense. You don't have control over the branch name anyway when\n> cloning, so it's nonsensical to print that advise. Another subsequent\n> step could be to turn the `advise()` into `advise_if_enabled()`, but\n> that change isn't really needed for git-clone(1) because there wouldn't\n> ever be a reason to print it.\n\nAs you mentioned, in this specific situation printing the advice\ndoesn't make much sense. It would probably be a good idea to allow this\nmessage to be suppressed from other call sites if requested to do so\nthough. I'll add another patch that turns it into `advise_if_enabled()`\nto support this.\n\n> Do we want to add a test somewhere that demonstrates that we don't print\n> the advise anymore?\n\nYa, I'll go ahead and include this in my next version.\n\nThanks,\n-Justin\n"},{"id":"514814","messageId":"yyeid3njdsmws7rl3kcsxne52fuadd7q4emqdlvatwvcrnyl42@rfnk26mvcgoa","threadId":"63163","inReplyTo":"926210f4-a8ff-4ac2-8b7f-85cd5598d77b@gmail.com","subject":"Re: [PATCH 0/2] clone: suppress unexpected advice message during clone","fromName":"Justin Tobler","fromEmail":"jltobler@gmail.com","sentAt":"2025-03-20T23:48:21Z","receivedAt":"2025-03-20T23:51:57Z","isPatch":true,"sender":{"key":"jltobler@gmail.com","avatar":"https://avatars.githubusercontent.com/u/53454972?v=4"},"body":"On 25/03/20 11:10AM, Phillip Wood wrote:\n> Hi Justin\n> \n> On 20/03/2025 01:46, Justin Tobler wrote:\n> > \n> > A side-effect of this change is that the location of the first\n> > `git_default_branch_name()` gets deferred to a later point of execution.\n> > This matters because `git_default_branch_name()` only computes the\n> > default branch name once and returns a cached value for subsequent\n> > invocations. After this change, the `git_default_branch_name()` call\n> > site that actually computes the value becomes `guess_remote_head()` and\n> > is configured to always show the advice message.\n> \n> Isn't the fundamental cause of this bug that advise() ignores GIT_ADVICE?\n> I'm not really clear why \"git --no-advice\" only applies to advice that is\n> guarded by advice_enabled() when it is documented as disabling all advice\n> hints.\n\nFrom my point of view, this advice message should never be presented in\nthis particular scenario regardless of the configuration as it doesn't\nmake much sense here. This also happens to be the original behavior so I\nthink we should probably return to that state.\n\nI was also a bit suprised to see that not all advice messages respect\nthe `--no-advice` option. I'm not sure if there is a reason for this, or if\n`advise_if_enabled()` just came later and not everything was converted.\n\nIn general though, other users of the default branch name advice message\nshould probably follow the `--no-advice` option. I'll add another patch\nthat does this in the next version.\n\nThanks,\n-Justin\n"},{"id":"514826","messageId":"xmqqjz8ivk7t.fsf@gitster.g","threadId":"63163","inReplyTo":"Z9ukDuvsLXhYTQAP@pks.im","subject":"Re: [PATCH 1/2] remote: allow `guess_remote_head()` to suppress advice","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2025-03-21T08:52:54Z","receivedAt":"2025-03-21T08:52:57Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Patrick Steinhardt <ps@pks.im> writes:\n\n> On Wed, Mar 19, 2025 at 08:46:45PM -0500, Justin Tobler wrote:\n>> diff --git a/remote.h b/remote.h\n>> index 6be5031f64..49c7b644bb 100644\n>> --- a/remote.h\n>> +++ b/remote.h\n>> @@ -395,7 +395,7 @@ struct ref *get_local_heads(void);\n>>   */\n>>  struct ref *guess_remote_head(const struct ref *head,\n>>  \t\t\t      const struct ref *refs,\n>> -\t\t\t      int all);\n>> +\t\t\t      int all, int quiet);\n>\n> I think instead of introducing another boolean parameter it would be\n> preferable to have a preparatory commit that turns `all` into `flags`.\n\nGood.  And when we turn that into a set of bits \"flags\", make sure\nwe make it unsigned, not signed int.\n\nThanks.\n"},{"id":"514837","messageId":"1849284e-b5cc-40fd-ba59-43559a20ac2e@gmail.com","threadId":"63163","inReplyTo":"yyeid3njdsmws7rl3kcsxne52fuadd7q4emqdlvatwvcrnyl42@rfnk26mvcgoa","subject":"Re: [PATCH 0/2] clone: suppress unexpected advice message during clone","fromName":"Phillip Wood","fromEmail":"phillip.wood123@gmail.com","sentAt":"2025-03-21T16:42:10Z","receivedAt":"2025-03-21T16:42:14Z","isPatch":true,"sender":{"key":"phillip.wood@dunelm.org.uk","avatar":null},"body":"On 20/03/2025 23:48, Justin Tobler wrote:\n> On 25/03/20 11:10AM, Phillip Wood wrote:\n>> Hi Justin\n>>\n>> On 20/03/2025 01:46, Justin Tobler wrote:\n>>>\n>>> A side-effect of this change is that the location of the first\n>>> `git_default_branch_name()` gets deferred to a later point of execution.\n>>> This matters because `git_default_branch_name()` only computes the\n>>> default branch name once and returns a cached value for subsequent\n>>> invocations. After this change, the `git_default_branch_name()` call\n>>> site that actually computes the value becomes `guess_remote_head()` and\n>>> is configured to always show the advice message.\n>>\n>> Isn't the fundamental cause of this bug that advise() ignores GIT_ADVICE?\n>> I'm not really clear why \"git --no-advice\" only applies to advice that is\n>> guarded by advice_enabled() when it is documented as disabling all advice\n>> hints.\n> \n>  From my point of view, this advice message should never be presented in\n> this particular scenario regardless of the configuration as it doesn't\n> make much sense here. This also happens to be the original behavior so I\n> think we should probably return to that state.\n\nOh, good point. So the original report actually highlights two bugs - \nthe regression you're fixing here and the fact that \"--no-advice\" does \nnot suppress the advice.\n\n> I was also a bit suprised to see that not all advice messages respect\n> the `--no-advice` option. I'm not sure if there is a reason for this, or if\n> `advise_if_enabled()` just came later and not everything was converted.\n> \n> In general though, other users of the default branch name advice message\n> should probably follow the `--no-advice` option. I'll add another patch\n> that does this in the next version.\n\nThat would be great,\n\nThanks\n\nPhillip\n\n> Thanks,\n> -Justin\n> \n\n"},{"id":"514852","messageId":"20250321231639.180762-1-jltobler@gmail.com","threadId":"63163","inReplyTo":"20250320014646.2899791-1-jltobler@gmail.com","subject":"[PATCH v2 0/3] clone: suppress unexpected advice message during clone","fromName":"Justin Tobler","fromEmail":"jltobler@gmail.com","sentAt":"2025-03-21T23:16:36Z","receivedAt":"2025-03-21T23:20:33Z","isPatch":true,"sender":{"key":"jltobler@gmail.com","avatar":"https://avatars.githubusercontent.com/u/53454972?v=4"},"body":"It has been reported[1] that starting in Git v2.45.0, cloning from a bundle\nresults in the default branch name advice message always being displayed\nwhen it was previously not. It can be reproduced by the following:\n\n        git init bundle-repo &&\n        git -C bundle-repo --allow-empty -m init &&\n        git -C bundle-repo bundle create ../repo.bundle --all &&\n        git clone repo.bundle bundle-clone\n\nThis issue bisects to 199f44cb2ead (builtin/clone: allow remote helpers\nto detect repo, 2024-02-27) where the refdb is partially initialized\nduring clones before remote helpers are executed. This partial\ninitilization creates the HEAD file and \"refs/\" directory.\n\nA side-effect of this change is that the location of the first\n`git_default_branch_name()` gets deferred to a later point of execution.\nThis matters because `git_default_branch_name()` only computes the\ndefault branch name once and returns a cached value for subsequent\ninvocations. After this change, the `git_default_branch_name()` call\nsite that actually computes the value becomes `guess_remote_head()` and\nis configured to always show the advice message.\n\nAlso, `guess_remote_head()` only invokes `git_default_branch_name()` in\ncases where the transport is unable to figure out the remote HEAD and\nmust guess. This explains why the advice message gets printed for bundle\nclones, but not all clones.\n\nThis series addresses the issue by adapting `guess_remote_head()` to\nsupport configuring the underlying `git_default_branch_name()`, which\nhas since been renamed to `repo_default_branch_name()`, to be quiet and\nsuppress the advice message.\n\nChanges since V1:\n\n        - Instead of adding an additional boolean to\n          `guess_remote_head()` to suppress the advice message, the\n          function is adapted to accepts flags that accoplish the same\n          thing.\n\n        - Added a test to validate that the advice message is not being\n          printed.\n\n        - While we are here, added another patch to allow the default\n          branch name advice message to be suppressrd by the\n          `--no-advice` option.\n\nThanks,\n-Justin\n\n[1]: <7EC98E2F-144D-4974-94F6-FC24B443651D@norbauer.com>\n\nJustin Tobler (3):\n  remote: allow `guess_remote_head()` to suppress advice\n  builtin/clone: suppress unexpected default branch advice\n  advice: allow disabling default branch name advice\n\n advice.c                |  1 +\n advice.h                |  1 +\n builtin/clone.c         |  3 ++-\n builtin/fetch.c         |  2 +-\n builtin/remote.c        |  2 +-\n refs.c                  |  3 ++-\n remote.c                | 10 ++++++----\n remote.h                | 11 +++++++----\n t/t0001-init.sh         |  8 ++++++++\n t/t5607-clone-bundle.sh | 12 ++++++++++++\n 10 files changed, 41 insertions(+), 12 deletions(-)\n\n\nbase-commit: 683c54c999c301c2cd6f715c411407c413b1d84e\n-- \n2.49.0\n\n"},{"id":"514854","messageId":"20250321231639.180762-2-jltobler@gmail.com","threadId":"63163","inReplyTo":"20250321231639.180762-1-jltobler@gmail.com","subject":"[PATCH v2 1/3] remote: allow `guess_remote_head()` to suppress advice","fromName":"Justin Tobler","fromEmail":"jltobler@gmail.com","sentAt":"2025-03-21T23:16:37Z","receivedAt":"2025-03-21T23:20:34Z","isPatch":true,"sender":{"key":"jltobler@gmail.com","avatar":"https://avatars.githubusercontent.com/u/53454972?v=4"},"body":"The `repo_default_branch_name()` invoked through `guess_remote_head()`\nis configured to always display the default branch advice message.\n\nAdapt `guess_remote_head()` to accept flags and convert the `all`\nparameter to a flag. Add the `REMOTE_GUESS_HEAD_QUIET` flag to to enable\nsuppression of advice messages. Call sites are updated accordingly.\n\nSigned-off-by: Justin Tobler <jltobler@gmail.com>\n---\n builtin/fetch.c  |  2 +-\n builtin/remote.c |  2 +-\n remote.c         | 10 ++++++----\n remote.h         | 11 +++++++----\n 4 files changed, 15 insertions(+), 10 deletions(-)\n\ndiff --git a/builtin/fetch.c b/builtin/fetch.c\nindex 95fd0018b9..763314bfcb 100644\n--- a/builtin/fetch.c\n+++ b/builtin/fetch.c\n@@ -1638,7 +1638,7 @@ static int set_head(const struct ref *remote_refs, struct remote *remote)\n \n \tget_fetch_map(remote_refs, &refspec, &fetch_map_tail, 0);\n \tmatches = guess_remote_head(find_ref_by_name(remote_refs, \"HEAD\"),\n-\t\t\t\t    fetch_map, 1);\n+\t\t\t\t    fetch_map, REMOTE_GUESS_HEAD_ALL);\n \tfor (ref = matches; ref; ref = ref->next) {\n \t\tstring_list_append(&heads, strip_refshead(ref->name));\n \t}\ndiff --git a/builtin/remote.c b/builtin/remote.c\nindex 1b7aad8838..d2aeb5ba1f 100644\n--- a/builtin/remote.c\n+++ b/builtin/remote.c\n@@ -511,7 +511,7 @@ static int get_head_names(const struct ref *remote_refs, struct ref_states *stat\n \n \tget_fetch_map(remote_refs, &refspec, &fetch_map_tail, 0);\n \tmatches = guess_remote_head(find_ref_by_name(remote_refs, \"HEAD\"),\n-\t\t\t\t    fetch_map, 1);\n+\t\t\t\t    fetch_map, REMOTE_GUESS_HEAD_ALL);\n \tfor (ref = matches; ref; ref = ref->next)\n \t\tstring_list_append(&states->heads, abbrev_branch(ref->name));\n \ndiff --git a/remote.c b/remote.c\nindex e609cf5c56..1db88beaf3 100644\n--- a/remote.c\n+++ b/remote.c\n@@ -2297,7 +2297,7 @@ struct ref *get_local_heads(void)\n \n struct ref *guess_remote_head(const struct ref *head,\n \t\t\t      const struct ref *refs,\n-\t\t\t      int all)\n+\t\t\t      unsigned flags)\n {\n \tconst struct ref *r;\n \tstruct ref *list = NULL;\n@@ -2315,8 +2315,10 @@ struct ref *guess_remote_head(const struct ref *head,\n \t\treturn copy_ref(find_ref_by_name(refs, head->symref));\n \n \t/* If a remote branch exists with the default branch name, let's use it. */\n-\tif (!all) {\n-\t\tchar *default_branch = repo_default_branch_name(the_repository, 0);\n+\tif (!(flags & REMOTE_GUESS_HEAD_ALL)) {\n+\t\tchar *default_branch =\n+\t\t\trepo_default_branch_name(the_repository,\n+\t\t\t\t\t\t flags & REMOTE_GUESS_HEAD_QUIET);\n \t\tchar *ref = xstrfmt(\"refs/heads/%s\", default_branch);\n \n \t\tr = find_ref_by_name(refs, ref);\n@@ -2339,7 +2341,7 @@ struct ref *guess_remote_head(const struct ref *head,\n \t\t    oideq(&r->old_oid, &head->old_oid)) {\n \t\t\t*tail = copy_ref(r);\n \t\t\ttail = &((*tail)->next);\n-\t\t\tif (!all)\n+\t\t\tif (!(flags & REMOTE_GUESS_HEAD_ALL))\n \t\t\t\tbreak;\n \t\t}\n \t}\ndiff --git a/remote.h b/remote.h\nindex 6be5031f64..7e4943ae3a 100644\n--- a/remote.h\n+++ b/remote.h\n@@ -387,15 +387,18 @@ int format_tracking_info(struct branch *branch, struct strbuf *sb,\n \t\t\t int show_divergence_advice);\n \n struct ref *get_local_heads(void);\n+\n /*\n  * Find refs from a list which are likely to be pointed to by the given HEAD\n- * ref. If 'all' is false, returns the most likely ref; otherwise, returns a\n- * list of all candidate refs. If no match is found (or 'head' is NULL),\n- * returns NULL. All returns are newly allocated and should be freed.\n+ * ref. If REMOTE_GUESS_HEAD_ALL is set, return a list of all candidate refs;\n+ * otherwise, return the most likely ref. If no match is found (or 'head' is\n+ * NULL), returns NULL. All returns are newly allocated and should be freed.\n  */\n+#define REMOTE_GUESS_HEAD_ALL\t(1 << 0)\n+#define REMOTE_GUESS_HEAD_QUIET (1 << 1)\n struct ref *guess_remote_head(const struct ref *head,\n \t\t\t      const struct ref *refs,\n-\t\t\t      int all);\n+\t\t\t      unsigned flags);\n \n /* Return refs which no longer exist on remote */\n struct ref *get_stale_heads(struct refspec *rs, struct ref *fetch_map);\n-- \n2.49.0\n\n"},{"id":"514853","messageId":"20250321231639.180762-3-jltobler@gmail.com","threadId":"63163","inReplyTo":"20250321231639.180762-1-jltobler@gmail.com","subject":"[PATCH v2 2/3] builtin/clone: suppress unexpected default branch advice","fromName":"Justin Tobler","fromEmail":"jltobler@gmail.com","sentAt":"2025-03-21T23:16:38Z","receivedAt":"2025-03-21T23:20:35Z","isPatch":true,"sender":{"key":"jltobler@gmail.com","avatar":"https://avatars.githubusercontent.com/u/53454972?v=4"},"body":"In 199f44cb2ead (builtin/clone: allow remote helpers to detect repo,\n2024-02-27), clones started partially initializing the refdb before\nexecuting the remote helpers by creating a HEAD file and \"refs/\"\ndirectory. This has resulted in some scenarios where git-clone(1) now\nprints the default branch name advice message where it previously did\nnot.\n\nA side-effect of the HEAD file already existing, is that computation of\nthe default branch name is handled later in execution. This matters\nbecause prior to 97abaab5f6 (refs: drop `git_default_branch_name()`,\n2024-05-17), the default branch value would be computed during its first\nexecution and cached. Subsequent invocations would simply return the\ncached value. Since the next `git_default_branch_name()` call site,\nwhich is invoked through `guess_remote_head()`, is not configured to\nsuppress the advice message, computing the default branch name results\nin the advice message being printed.\n\nConfigure `guess_remote_head()` to suppress the advice message,\nrestoring the previous behavior.\n\nSigned-off-by: Justin Tobler <jltobler@gmail.com>\n---\n builtin/clone.c         |  3 ++-\n t/t5607-clone-bundle.sh | 12 ++++++++++++\n 2 files changed, 14 insertions(+), 1 deletion(-)\n\ndiff --git a/builtin/clone.c b/builtin/clone.c\nindex f14229abf4..a4008715ec 100644\n--- a/builtin/clone.c\n+++ b/builtin/clone.c\n@@ -1523,7 +1523,8 @@ int cmd_clone(int argc,\n \t}\n \n \tremote_head = find_ref_by_name(refs, \"HEAD\");\n-\tremote_head_points_at = guess_remote_head(remote_head, mapped_refs, 0);\n+\tremote_head_points_at = guess_remote_head(remote_head, mapped_refs,\n+\t\t\t\t\t\t  REMOTE_GUESS_HEAD_QUIET);\n \n \tif (option_branch) {\n \t\tour_head_points_at = find_remote_branch(mapped_refs, option_branch);\ndiff --git a/t/t5607-clone-bundle.sh b/t/t5607-clone-bundle.sh\nindex 82e3621ec5..f526bb1c69 100755\n--- a/t/t5607-clone-bundle.sh\n+++ b/t/t5607-clone-bundle.sh\n@@ -211,4 +211,16 @@ test_expect_success 'git bundle v3 rejects unknown capabilities' '\n \ttest_grep \"unknown capability .unknown=silly.\" output\n '\n \n+test_expect_success 'cloning bundle suppresses default branch name advice' '\n+\ttest_when_finished \"rm -rf bundle-repo clone-repo\" &&\n+\n+\tgit init bundle-repo &&\n+\tgit -C bundle-repo commit --allow-empty -m init &&\n+\tgit -C bundle-repo bundle create repo.bundle --all &&\n+\tGIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \\\n+\t\tgit clone bundle-repo/repo.bundle clone-repo 2>err &&\n+\n+\ttest_grep ! \"hint: \" err\n+'\n+\n test_done\n-- \n2.49.0\n\n"},{"id":"514855","messageId":"20250321231639.180762-4-jltobler@gmail.com","threadId":"63163","inReplyTo":"20250321231639.180762-1-jltobler@gmail.com","subject":"[PATCH v2 3/3] advice: allow disabling default branch name advice","fromName":"Justin Tobler","fromEmail":"jltobler@gmail.com","sentAt":"2025-03-21T23:16:39Z","receivedAt":"2025-03-21T23:20:36Z","isPatch":true,"sender":{"key":"jltobler@gmail.com","avatar":"https://avatars.githubusercontent.com/u/53454972?v=4"},"body":"The default branch name advice message is displayed when\n`repo_default_branch_name()` is invoked and the `init.defaultBranch`\nconfig is not set. In this scenario, the advice message is always shown\neven if the `--no-advice` option is used.\n\nAdapt `repo_default_branch_name()` to allow the default branch name\nadvice message to be disabled with the `--no-advice` option and\ncorresponding configuration.\n\nSigned-off-by: Justin Tobler <jltobler@gmail.com>\n---\n advice.c        | 1 +\n advice.h        | 1 +\n refs.c          | 3 ++-\n t/t0001-init.sh | 8 ++++++++\n 4 files changed, 12 insertions(+), 1 deletion(-)\n\ndiff --git a/advice.c b/advice.c\nindex 1df43b7536..e5f0ff8449 100644\n--- a/advice.c\n+++ b/advice.c\n@@ -51,6 +51,7 @@ static struct {\n \t[ADVICE_AM_WORK_DIR] \t\t\t\t= { \"amWorkDir\" },\n \t[ADVICE_CHECKOUT_AMBIGUOUS_REMOTE_BRANCH_NAME] \t= { \"checkoutAmbiguousRemoteBranchName\" },\n \t[ADVICE_COMMIT_BEFORE_MERGE]\t\t\t= { \"commitBeforeMerge\" },\n+\t[ADVICE_DEFAULT_BRANCH_NAME]\t\t\t= { \"defaultBranchName\" },\n \t[ADVICE_DETACHED_HEAD]\t\t\t\t= { \"detachedHead\" },\n \t[ADVICE_DIVERGING]\t\t\t\t= { \"diverging\" },\n \t[ADVICE_FETCH_SET_HEAD_WARN]\t\t\t= { \"fetchRemoteHEADWarn\" },\ndiff --git a/advice.h b/advice.h\nindex d233cfc693..727dcecf4a 100644\n--- a/advice.h\n+++ b/advice.h\n@@ -18,6 +18,7 @@ enum advice_type {\n \tADVICE_AM_WORK_DIR,\n \tADVICE_CHECKOUT_AMBIGUOUS_REMOTE_BRANCH_NAME,\n \tADVICE_COMMIT_BEFORE_MERGE,\n+\tADVICE_DEFAULT_BRANCH_NAME,\n \tADVICE_DETACHED_HEAD,\n \tADVICE_DIVERGING,\n \tADVICE_FETCH_SET_HEAD_WARN,\ndiff --git a/refs.c b/refs.c\nindex 118465271d..bf9a40d6af 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -664,7 +664,8 @@ char *repo_default_branch_name(struct repository *r, int quiet)\n \tif (!ret) {\n \t\tret = xstrdup(\"master\");\n \t\tif (!quiet)\n-\t\t\tadvise(_(default_branch_name_advice), ret);\n+\t\t\tadvise_if_enabled(ADVICE_DEFAULT_BRANCH_NAME,\n+\t\t\t\t\t  _(default_branch_name_advice), ret);\n \t}\n \n \tfull_ref = xstrfmt(\"refs/heads/%s\", ret);\ndiff --git a/t/t0001-init.sh b/t/t0001-init.sh\nindex c49d9e0d38..f11a40811f 100755\n--- a/t/t0001-init.sh\n+++ b/t/t0001-init.sh\n@@ -830,6 +830,14 @@ test_expect_success 'advice on unconfigured init.defaultBranch' '\n \ttest_grep \"<YELLOW>hint: \" decoded\n '\n \n+test_expect_success 'advice on unconfigured init.defaultBranch disabled' '\n+\ttest_when_finished \"rm -rf no-advice\" &&\n+\n+\tGIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \\\n+\t\tgit -c advice.defaultBranchName=false init no-advice 2>err &&\n+\ttest_grep ! \"hint: \" err\n+'\n+\n test_expect_success 'overridden default main branch name (env)' '\n \ttest_config_global init.defaultBranch nmb &&\n \tGIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=env git init main-branch-env &&\n-- \n2.49.0\n\n"},{"id":"514882","messageId":"xmqqtt7jr10k.fsf@gitster.g","threadId":"63163","inReplyTo":"20250321231639.180762-1-jltobler@gmail.com","subject":"Re: [PATCH v2 0/3] clone: suppress unexpected advice message during clone","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2025-03-23T19:38:03Z","receivedAt":"2025-03-23T19:38:07Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Justin Tobler <jltobler@gmail.com> writes:\n\n> It has been reported[1] that starting in Git v2.45.0, cloning from a bundle\n> results in the default branch name advice message always being displayed\n> when it was previously not. It can be reproduced by the following:\n>\n>         git init bundle-repo &&\n>         git -C bundle-repo --allow-empty -m init &&\n\nPresumably this is \"commit --allow-empty -m init\" in the bundle-repo\nrepository?\n\n>         git -C bundle-repo bundle create ../repo.bundle --all &&\n>         git clone repo.bundle bundle-clone\n>\n> This issue bisects to 199f44cb2ead (builtin/clone: allow remote helpers\n> ...\n> This series addresses the issue by adapting `guess_remote_head()` to\n> support configuring the underlying `git_default_branch_name()`, which\n> has since been renamed to `repo_default_branch_name()`, to be quiet and\n> suppress the advice message.\n\nNicely analyzed and described.\n\n> Changes since V1:\n>\n>         - Instead of adding an additional boolean to\n>           `guess_remote_head()` to suppress the advice message, the\n>           function is adapted to accepts flags that accoplish the same\n>           thing.\n>\n>         - Added a test to validate that the advice message is not being\n>           printed.\n>\n>         - While we are here, added another patch to allow the default\n>           branch name advice message to be suppressrd by the\n>           `--no-advice` option.\n>\n> Thanks,\n> -Justin\n\n>\n> [1]: <7EC98E2F-144D-4974-94F6-FC24B443651D@norbauer.com>\n>\n> Justin Tobler (3):\n>   remote: allow `guess_remote_head()` to suppress advice\n>   builtin/clone: suppress unexpected default branch advice\n>   advice: allow disabling default branch name advice\n>\n>  advice.c                |  1 +\n>  advice.h                |  1 +\n>  builtin/clone.c         |  3 ++-\n>  builtin/fetch.c         |  2 +-\n>  builtin/remote.c        |  2 +-\n>  refs.c                  |  3 ++-\n>  remote.c                | 10 ++++++----\n>  remote.h                | 11 +++++++----\n>  t/t0001-init.sh         |  8 ++++++++\n>  t/t5607-clone-bundle.sh | 12 ++++++++++++\n>  10 files changed, 41 insertions(+), 12 deletions(-)\n>\n>\n> base-commit: 683c54c999c301c2cd6f715c411407c413b1d84e\n"},{"id":"514906","messageId":"106cecbf-6a7c-46bd-8115-2b5fb06cc9af@gmail.com","threadId":"63163","inReplyTo":"20250321231639.180762-2-jltobler@gmail.com","subject":"Re: [PATCH v2 1/3] remote: allow `guess_remote_head()` to suppress advice","fromName":"Phillip Wood","fromEmail":"phillip.wood123@gmail.com","sentAt":"2025-03-24T09:31:53Z","receivedAt":"2025-03-24T09:31:58Z","isPatch":true,"sender":{"key":"phillip.wood@dunelm.org.uk","avatar":null},"body":"Hi Justin\n\nOn 21/03/2025 23:16, Justin Tobler wrote:\n> The `repo_default_branch_name()` invoked through `guess_remote_head()`\n> is configured to always display the default branch advice message.\n> \n> Adapt `guess_remote_head()` to accept flags and convert the `all`\n> parameter to a flag. \n\nThis makes sense if we want to convert the boolean argument to a flags \nargument. However the only callers that do not set `all` when calling \nthis function are in git clone where we don't want to emit the warning. \nIt is probably not worth a re-roll but I wonder if we really need to do \nthis conversion or if we should just hard code guess_remote_head() to be \nquiet when it calls repo_default_branch_name()\n\nBest Wishes\n\nPhillip\n\n> Add the `REMOTE_GUESS_HEAD_QUIET` flag to to enable\n> suppression of advice messages. Call sites are updated accordingly.\n> > Signed-off-by: Justin Tobler <jltobler@gmail.com>\n> ---\n>   builtin/fetch.c  |  2 +-\n>   builtin/remote.c |  2 +-\n>   remote.c         | 10 ++++++----\n>   remote.h         | 11 +++++++----\n>   4 files changed, 15 insertions(+), 10 deletions(-)\n> \n> diff --git a/builtin/fetch.c b/builtin/fetch.c\n> index 95fd0018b9..763314bfcb 100644\n> --- a/builtin/fetch.c\n> +++ b/builtin/fetch.c\n> @@ -1638,7 +1638,7 @@ static int set_head(const struct ref *remote_refs, struct remote *remote)\n>   \n>   \tget_fetch_map(remote_refs, &refspec, &fetch_map_tail, 0);\n>   \tmatches = guess_remote_head(find_ref_by_name(remote_refs, \"HEAD\"),\n> -\t\t\t\t    fetch_map, 1);\n> +\t\t\t\t    fetch_map, REMOTE_GUESS_HEAD_ALL);\n>   \tfor (ref = matches; ref; ref = ref->next) {\n>   \t\tstring_list_append(&heads, strip_refshead(ref->name));\n>   \t}\n> diff --git a/builtin/remote.c b/builtin/remote.c\n> index 1b7aad8838..d2aeb5ba1f 100644\n> --- a/builtin/remote.c\n> +++ b/builtin/remote.c\n> @@ -511,7 +511,7 @@ static int get_head_names(const struct ref *remote_refs, struct ref_states *stat\n>   \n>   \tget_fetch_map(remote_refs, &refspec, &fetch_map_tail, 0);\n>   \tmatches = guess_remote_head(find_ref_by_name(remote_refs, \"HEAD\"),\n> -\t\t\t\t    fetch_map, 1);\n> +\t\t\t\t    fetch_map, REMOTE_GUESS_HEAD_ALL);\n>   \tfor (ref = matches; ref; ref = ref->next)\n>   \t\tstring_list_append(&states->heads, abbrev_branch(ref->name));\n>   \n> diff --git a/remote.c b/remote.c\n> index e609cf5c56..1db88beaf3 100644\n> --- a/remote.c\n> +++ b/remote.c\n> @@ -2297,7 +2297,7 @@ struct ref *get_local_heads(void)\n>   \n>   struct ref *guess_remote_head(const struct ref *head,\n>   \t\t\t      const struct ref *refs,\n> -\t\t\t      int all)\n> +\t\t\t      unsigned flags)\n>   {\n>   \tconst struct ref *r;\n>   \tstruct ref *list = NULL;\n> @@ -2315,8 +2315,10 @@ struct ref *guess_remote_head(const struct ref *head,\n>   \t\treturn copy_ref(find_ref_by_name(refs, head->symref));\n>   \n>   \t/* If a remote branch exists with the default branch name, let's use it. */\n> -\tif (!all) {\n> -\t\tchar *default_branch = repo_default_branch_name(the_repository, 0);\n> +\tif (!(flags & REMOTE_GUESS_HEAD_ALL)) {\n> +\t\tchar *default_branch =\n> +\t\t\trepo_default_branch_name(the_repository,\n> +\t\t\t\t\t\t flags & REMOTE_GUESS_HEAD_QUIET);\n>   \t\tchar *ref = xstrfmt(\"refs/heads/%s\", default_branch);\n>   \n>   \t\tr = find_ref_by_name(refs, ref);\n> @@ -2339,7 +2341,7 @@ struct ref *guess_remote_head(const struct ref *head,\n>   \t\t    oideq(&r->old_oid, &head->old_oid)) {\n>   \t\t\t*tail = copy_ref(r);\n>   \t\t\ttail = &((*tail)->next);\n> -\t\t\tif (!all)\n> +\t\t\tif (!(flags & REMOTE_GUESS_HEAD_ALL))\n>   \t\t\t\tbreak;\n>   \t\t}\n>   \t}\n> diff --git a/remote.h b/remote.h\n> index 6be5031f64..7e4943ae3a 100644\n> --- a/remote.h\n> +++ b/remote.h\n> @@ -387,15 +387,18 @@ int format_tracking_info(struct branch *branch, struct strbuf *sb,\n>   \t\t\t int show_divergence_advice);\n>   \n>   struct ref *get_local_heads(void);\n> +\n>   /*\n>    * Find refs from a list which are likely to be pointed to by the given HEAD\n> - * ref. If 'all' is false, returns the most likely ref; otherwise, returns a\n> - * list of all candidate refs. If no match is found (or 'head' is NULL),\n> - * returns NULL. All returns are newly allocated and should be freed.\n> + * ref. If REMOTE_GUESS_HEAD_ALL is set, return a list of all candidate refs;\n> + * otherwise, return the most likely ref. If no match is found (or 'head' is\n> + * NULL), returns NULL. All returns are newly allocated and should be freed.\n>    */\n> +#define REMOTE_GUESS_HEAD_ALL\t(1 << 0)\n> +#define REMOTE_GUESS_HEAD_QUIET (1 << 1)\n>   struct ref *guess_remote_head(const struct ref *head,\n>   \t\t\t      const struct ref *refs,\n> -\t\t\t      int all);\n> +\t\t\t      unsigned flags);\n>   \n>   /* Return refs which no longer exist on remote */\n>   struct ref *get_stale_heads(struct refspec *rs, struct ref *fetch_map);\n\n"},{"id":"514907","messageId":"966aa1cc-fd4a-42b7-a241-0537767021ed@gmail.com","threadId":"63163","inReplyTo":"20250321231639.180762-3-jltobler@gmail.com","subject":"Re: [PATCH v2 2/3] builtin/clone: suppress unexpected default branch advice","fromName":"Phillip Wood","fromEmail":"phillip.wood123@gmail.com","sentAt":"2025-03-24T09:32:18Z","receivedAt":"2025-03-24T09:32:21Z","isPatch":true,"sender":{"key":"phillip.wood@dunelm.org.uk","avatar":null},"body":"Hi Justin\n\nOn 21/03/2025 23:16, Justin Tobler wrote:\n> In 199f44cb2ead (builtin/clone: allow remote helpers to detect repo,\n> 2024-02-27), clones started partially initializing the refdb before\n> executing the remote helpers by creating a HEAD file and \"refs/\"\n> directory. This has resulted in some scenarios where git-clone(1) now\n> prints the default branch name advice message where it previously did\n> not.\n> \n> A side-effect of the HEAD file already existing, is that computation of\n> the default branch name is handled later in execution. This matters\n> because prior to 97abaab5f6 (refs: drop `git_default_branch_name()`,\n> 2024-05-17), the default branch value would be computed during its first\n> execution and cached. Subsequent invocations would simply return the\n> cached value. Since the next `git_default_branch_name()` call site,\n> which is invoked through `guess_remote_head()`, is not configured to\n> suppress the advice message, computing the default branch name results\n> in the advice message being printed.\n> \n> Configure `guess_remote_head()` to suppress the advice message,\n> restoring the previous behavior.\n> \n> Signed-off-by: Justin Tobler <jltobler@gmail.com>\n> ---\n>   builtin/clone.c         |  3 ++-\n>   t/t5607-clone-bundle.sh | 12 ++++++++++++\n>   2 files changed, 14 insertions(+), 1 deletion(-)\n> \n> diff --git a/builtin/clone.c b/builtin/clone.c\n> index f14229abf4..a4008715ec 100644\n> --- a/builtin/clone.c\n> +++ b/builtin/clone.c\n> @@ -1523,7 +1523,8 @@ int cmd_clone(int argc,\n>   \t}\n>   \n>   \tremote_head = find_ref_by_name(refs, \"HEAD\");\n> -\tremote_head_points_at = guess_remote_head(remote_head, mapped_refs, 0);\n> +\tremote_head_points_at = guess_remote_head(remote_head, mapped_refs,\n> +\t\t\t\t\t\t  REMOTE_GUESS_HEAD_QUIET);\n\nThere is another caller of guess_remote_head() in wanted_peer_refs() \nwhich I think we probably want to be quiet as well. I don't see how it \nis helpful to the user to prompt them about setting the default branch \nname used when creating local repositories during a clone of a remote \nrepository.\n\nBest Wishes\n\nPhillip\n\n>   \n>   \tif (option_branch) {\n>   \t\tour_head_points_at = find_remote_branch(mapped_refs, option_branch);\n> diff --git a/t/t5607-clone-bundle.sh b/t/t5607-clone-bundle.sh\n> index 82e3621ec5..f526bb1c69 100755\n> --- a/t/t5607-clone-bundle.sh\n> +++ b/t/t5607-clone-bundle.sh\n> @@ -211,4 +211,16 @@ test_expect_success 'git bundle v3 rejects unknown capabilities' '\n>   \ttest_grep \"unknown capability .unknown=silly.\" output\n>   '\n>   \n> +test_expect_success 'cloning bundle suppresses default branch name advice' '\n> +\ttest_when_finished \"rm -rf bundle-repo clone-repo\" &&\n> +\n> +\tgit init bundle-repo &&\n> +\tgit -C bundle-repo commit --allow-empty -m init &&\n> +\tgit -C bundle-repo bundle create repo.bundle --all &&\n> +\tGIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \\\n> +\t\tgit clone bundle-repo/repo.bundle clone-repo 2>err &&\n> +\n> +\ttest_grep ! \"hint: \" err\n> +'\n> +\n>   test_done\n\n"},{"id":"514908","messageId":"16a8af3d-151b-489d-a693-3cd2658c45ef@gmail.com","threadId":"63163","inReplyTo":"20250321231639.180762-4-jltobler@gmail.com","subject":"Re: [PATCH v2 3/3] advice: allow disabling default branch name advice","fromName":"Phillip Wood","fromEmail":"phillip.wood123@gmail.com","sentAt":"2025-03-24T09:32:24Z","receivedAt":"2025-03-24T09:32:26Z","isPatch":true,"sender":{"key":"phillip.wood@dunelm.org.uk","avatar":null},"body":"Hi Justin\n\nOn 21/03/2025 23:16, Justin Tobler wrote:\n> The default branch name advice message is displayed when\n> `repo_default_branch_name()` is invoked and the `init.defaultBranch`\n> config is not set. In this scenario, the advice message is always shown\n> even if the `--no-advice` option is used.\n> \n> Adapt `repo_default_branch_name()` to allow the default branch name\n> advice message to be disabled with the `--no-advice` option and\n> corresponding configuration.\n\nThanks for adding this, it has always bothered me that the only way to \nsilence this hint was by setting a default branch name, rather than \nbeing able to just accept git's default by setting the appropiate advice \nvariable. The patch looks good to me\n\nBest Wishes\n\nPhillip\n\n> Signed-off-by: Justin Tobler <jltobler@gmail.com>\n> ---\n>   advice.c        | 1 +\n>   advice.h        | 1 +\n>   refs.c          | 3 ++-\n>   t/t0001-init.sh | 8 ++++++++\n>   4 files changed, 12 insertions(+), 1 deletion(-)\n> \n> diff --git a/advice.c b/advice.c\n> index 1df43b7536..e5f0ff8449 100644\n> --- a/advice.c\n> +++ b/advice.c\n> @@ -51,6 +51,7 @@ static struct {\n>   \t[ADVICE_AM_WORK_DIR] \t\t\t\t= { \"amWorkDir\" },\n>   \t[ADVICE_CHECKOUT_AMBIGUOUS_REMOTE_BRANCH_NAME] \t= { \"checkoutAmbiguousRemoteBranchName\" },\n>   \t[ADVICE_COMMIT_BEFORE_MERGE]\t\t\t= { \"commitBeforeMerge\" },\n> +\t[ADVICE_DEFAULT_BRANCH_NAME]\t\t\t= { \"defaultBranchName\" },\n>   \t[ADVICE_DETACHED_HEAD]\t\t\t\t= { \"detachedHead\" },\n>   \t[ADVICE_DIVERGING]\t\t\t\t= { \"diverging\" },\n>   \t[ADVICE_FETCH_SET_HEAD_WARN]\t\t\t= { \"fetchRemoteHEADWarn\" },\n> diff --git a/advice.h b/advice.h\n> index d233cfc693..727dcecf4a 100644\n> --- a/advice.h\n> +++ b/advice.h\n> @@ -18,6 +18,7 @@ enum advice_type {\n>   \tADVICE_AM_WORK_DIR,\n>   \tADVICE_CHECKOUT_AMBIGUOUS_REMOTE_BRANCH_NAME,\n>   \tADVICE_COMMIT_BEFORE_MERGE,\n> +\tADVICE_DEFAULT_BRANCH_NAME,\n>   \tADVICE_DETACHED_HEAD,\n>   \tADVICE_DIVERGING,\n>   \tADVICE_FETCH_SET_HEAD_WARN,\n> diff --git a/refs.c b/refs.c\n> index 118465271d..bf9a40d6af 100644\n> --- a/refs.c\n> +++ b/refs.c\n> @@ -664,7 +664,8 @@ char *repo_default_branch_name(struct repository *r, int quiet)\n>   \tif (!ret) {\n>   \t\tret = xstrdup(\"master\");\n>   \t\tif (!quiet)\n> -\t\t\tadvise(_(default_branch_name_advice), ret);\n> +\t\t\tadvise_if_enabled(ADVICE_DEFAULT_BRANCH_NAME,\n> +\t\t\t\t\t  _(default_branch_name_advice), ret);\n>   \t}\n>   \n>   \tfull_ref = xstrfmt(\"refs/heads/%s\", ret);\n> diff --git a/t/t0001-init.sh b/t/t0001-init.sh\n> index c49d9e0d38..f11a40811f 100755\n> --- a/t/t0001-init.sh\n> +++ b/t/t0001-init.sh\n> @@ -830,6 +830,14 @@ test_expect_success 'advice on unconfigured init.defaultBranch' '\n>   \ttest_grep \"<YELLOW>hint: \" decoded\n>   '\n>   \n> +test_expect_success 'advice on unconfigured init.defaultBranch disabled' '\n> +\ttest_when_finished \"rm -rf no-advice\" &&\n> +\n> +\tGIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \\\n> +\t\tgit -c advice.defaultBranchName=false init no-advice 2>err &&\n> +\ttest_grep ! \"hint: \" err\n> +'\n> +\n>   test_expect_success 'overridden default main branch name (env)' '\n>   \ttest_config_global init.defaultBranch nmb &&\n>   \tGIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=env git init main-branch-env &&\n\n"},{"id":"514952","messageId":"3rcpapodk473swxbdgubhuqijvgwe6rz5iqsfykglsmjbanuu7@mh6tvrhyyrx5","threadId":"63163","inReplyTo":"106cecbf-6a7c-46bd-8115-2b5fb06cc9af@gmail.com","subject":"Re: [PATCH v2 1/3] remote: allow `guess_remote_head()` to suppress advice","fromName":"Justin Tobler","fromEmail":"jltobler@gmail.com","sentAt":"2025-03-24T15:21:54Z","receivedAt":"2025-03-24T15:25:33Z","isPatch":true,"sender":{"key":"jltobler@gmail.com","avatar":"https://avatars.githubusercontent.com/u/53454972?v=4"},"body":"On 25/03/24 09:31AM, Phillip Wood wrote:\n> Hi Justin\n> \n> On 21/03/2025 23:16, Justin Tobler wrote:\n> > The `repo_default_branch_name()` invoked through `guess_remote_head()`\n> > is configured to always display the default branch advice message.\n> > \n> > Adapt `guess_remote_head()` to accept flags and convert the `all`\n> > parameter to a flag.\n> \n> This makes sense if we want to convert the boolean argument to a flags\n> argument. However the only callers that do not set `all` when calling this\n> function are in git clone where we don't want to emit the warning. It is\n> probably not worth a re-roll but I wonder if we really need to do this\n> conversion or if we should just hard code guess_remote_head() to be quiet\n> when it calls repo_default_branch_name()\n\nGood point. We could just rely on the fact that all current\n`guess_remote_head()` callers that do not set `all` also do not want the\nadvice to be printed.\n\nI have a slight preference to keep this as-is and favor the explicit\nconfiguration, but ultimately I don't feel strongly either way. I am\nopen to change in a followup version though. :)\n\nThanks,\n-Justin\n"},{"id":"514954","messageId":"w7kbqucqwajzo5q6qfty2o52tytvzkzsio755mz6cforuenaap@hx3zfd3nns6e","threadId":"63163","inReplyTo":"966aa1cc-fd4a-42b7-a241-0537767021ed@gmail.com","subject":"Re: [PATCH v2 2/3] builtin/clone: suppress unexpected default branch advice","fromName":"Justin Tobler","fromEmail":"jltobler@gmail.com","sentAt":"2025-03-24T15:35:45Z","receivedAt":"2025-03-24T15:39:25Z","isPatch":true,"sender":{"key":"jltobler@gmail.com","avatar":"https://avatars.githubusercontent.com/u/53454972?v=4"},"body":"On 25/03/24 09:32AM, Phillip Wood wrote:\n> Hi Justin\n> \n> On 21/03/2025 23:16, Justin Tobler wrote:\n> > In 199f44cb2ead (builtin/clone: allow remote helpers to detect repo,\n> > 2024-02-27), clones started partially initializing the refdb before\n> > executing the remote helpers by creating a HEAD file and \"refs/\"\n> > directory. This has resulted in some scenarios where git-clone(1) now\n> > prints the default branch name advice message where it previously did\n> > not.\n> > \n> > A side-effect of the HEAD file already existing, is that computation of\n> > the default branch name is handled later in execution. This matters\n> > because prior to 97abaab5f6 (refs: drop `git_default_branch_name()`,\n> > 2024-05-17), the default branch value would be computed during its first\n> > execution and cached. Subsequent invocations would simply return the\n> > cached value. Since the next `git_default_branch_name()` call site,\n> > which is invoked through `guess_remote_head()`, is not configured to\n> > suppress the advice message, computing the default branch name results\n> > in the advice message being printed.\n> > \n> > Configure `guess_remote_head()` to suppress the advice message,\n> > restoring the previous behavior.\n> > \n> > Signed-off-by: Justin Tobler <jltobler@gmail.com>\n> > ---\n> >   builtin/clone.c         |  3 ++-\n> >   t/t5607-clone-bundle.sh | 12 ++++++++++++\n> >   2 files changed, 14 insertions(+), 1 deletion(-)\n> > \n> > diff --git a/builtin/clone.c b/builtin/clone.c\n> > index f14229abf4..a4008715ec 100644\n> > --- a/builtin/clone.c\n> > +++ b/builtin/clone.c\n> > @@ -1523,7 +1523,8 @@ int cmd_clone(int argc,\n> >   \t}\n> >   \tremote_head = find_ref_by_name(refs, \"HEAD\");\n> > -\tremote_head_points_at = guess_remote_head(remote_head, mapped_refs, 0);\n> > +\tremote_head_points_at = guess_remote_head(remote_head, mapped_refs,\n> > +\t\t\t\t\t\t  REMOTE_GUESS_HEAD_QUIET);\n> \n> There is another caller of guess_remote_head() in wanted_peer_refs() which I\n> think we probably want to be quiet as well. I don't see how it is helpful to\n> the user to prompt them about setting the default branch name used when\n> creating local repositories during a clone of a remote repository.\n\nFor `wanted_peer_refs()` to invoke `guess_remote_head()`, the\n`--single-branch` option must be set. This means, outside of the bundle\nclone example, there is another way to get unexpected advice message to\nprint. Interestingly, if you perform a bundle clone with the\n`--single-branch` option, the same advice message prints twice.\n\nI'll send a followup version that also suppresses the unwanted advice\nmessage from `wanted_peer_refs()`.\n\nThanks,\n-Justin\n"},{"id":"514961","messageId":"884dc4b3-d470-46f6-b129-c6d20817daf7@gmail.com","threadId":"63163","inReplyTo":"3rcpapodk473swxbdgubhuqijvgwe6rz5iqsfykglsmjbanuu7@mh6tvrhyyrx5","subject":"Re: [PATCH v2 1/3] remote: allow `guess_remote_head()` to suppress advice","fromName":"","fromEmail":"phillip.wood123@gmail.com","sentAt":"2025-03-24T19:29:59Z","receivedAt":"2025-03-24T19:30:03Z","isPatch":true,"sender":{"key":"phillip.wood@dunelm.org.uk","avatar":null},"body":"Hi Justin\n\nOn 24/03/2025 15:21, Justin Tobler wrote:\n> On 25/03/24 09:31AM, Phillip Wood wrote:\n>> On 21/03/2025 23:16, Justin Tobler wrote:\n>>> The `repo_default_branch_name()` invoked through `guess_remote_head()`\n>>> is configured to always display the default branch advice message.\n>>>\n>>> Adapt `guess_remote_head()` to accept flags and convert the `all`\n>>> parameter to a flag.\n>>\n>> This makes sense if we want to convert the boolean argument to a flags\n>> argument. However the only callers that do not set `all` when calling this\n>> function are in git clone where we don't want to emit the warning. It is\n>> probably not worth a re-roll but I wonder if we really need to do this\n>> conversion or if we should just hard code guess_remote_head() to be quiet\n>> when it calls repo_default_branch_name()\n> \n> Good point. We could just rely on the fact that all current\n> `guess_remote_head()` callers that do not set `all` also do not want the\n> advice to be printed.\n> \n> I have a slight preference to keep this as-is and favor the explicit\n> configuration, but ultimately I don't feel strongly either way. I am\n> open to change in a followup version though. :)\n\nI'm fine either way so lets keep it as-is if you want\n\nThanks\n\nPhillip\n\n"},{"id":"514978","messageId":"20250325005148.1771502-1-jltobler@gmail.com","threadId":"63163","inReplyTo":"20250321231639.180762-1-jltobler@gmail.com","subject":"[PATCH v3 0/3] clone: suppress unexpected advice message during clone","fromName":"Justin Tobler","fromEmail":"jltobler@gmail.com","sentAt":"2025-03-25T00:51:45Z","receivedAt":"2025-03-25T00:55:33Z","isPatch":true,"sender":{"key":"jltobler@gmail.com","avatar":"https://avatars.githubusercontent.com/u/53454972?v=4"},"body":"It has been reported[1] that starting in Git v2.45.0, cloning from a bundle\nresults in the default branch name advice message always being displayed\nwhen it was previously not. It can be reproduced by the following:\n\n        git init bundle-repo &&\n        git -C bundle-repo commit --allow-empty -m init &&\n        git -C bundle-repo bundle create ../repo.bundle --all &&\n        git clone repo.bundle bundle-clone\n\nThis issue bisects to 199f44cb2ead (builtin/clone: allow remote helpers\nto detect repo, 2024-02-27) where the refdb is partially initialized\nduring clones before remote helpers are executed. This partial\ninitialization creates the HEAD file and \"refs/\" directory.\n\nA side-effect of this change is that the location of the first\n`git_default_branch_name()` gets deferred to a later point of execution.\nThis matters because `git_default_branch_name()` only computes the\ndefault branch name once and returns a cached value for subsequent\ninvocations. After this change, the `git_default_branch_name()` call\nsite that actually computes the value becomes `guess_remote_head()` and\nis configured to always show the advice message.\n\nAlso, `guess_remote_head()` only invokes `git_default_branch_name()` in\ncases where the transport is unable to figure out the remote HEAD and\nmust guess. This explains why the advice message gets printed for bundle\nclones, but not all clones.\n\nThis series addresses the issue by adapting `guess_remote_head()` to\nsupport configuring the underlying `git_default_branch_name()`, which\nhas since been renamed to `repo_default_branch_name()`, to be quiet and\nsuppress the advice message.\n\nChanges since V2:\n\n        - The default branch name advice message may also print with the\n          `--single-branch` option in certain scenarios. This instance\n          is also suppressed by setting the `REMOTE_GUESS_HEAD_QUIET`\n          flag for another `guess_remote_head()` call site invoked\n          during clones.\n\nChanges since V1:\n\n        - Instead of adding an additional boolean to\n          `guess_remote_head()` to suppress the advice message, the\n          function is adapted to accepts flags that accoplish the same\n          thing.\n\n        - Added a test to validate that the advice message is not being\n          printed.\n\n        - While we are here, added another patch to allow the default\n          branch name advice message to be suppressrd by the\n          `--no-advice` option.\n\nThanks,\n-Justin\n\n[1]: <7EC98E2F-144D-4974-94F6-FC24B443651D@norbauer.com>\n\nJustin Tobler (3):\n  remote: allow `guess_remote_head()` to suppress advice\n  builtin/clone: suppress unexpected default branch advice\n  advice: allow disabling default branch name advice\n\n advice.c                |  1 +\n advice.h                |  1 +\n builtin/clone.c         |  7 +++++--\n builtin/fetch.c         |  2 +-\n builtin/remote.c        |  2 +-\n refs.c                  |  3 ++-\n remote.c                | 10 ++++++----\n remote.h                | 11 +++++++----\n t/t0001-init.sh         |  8 ++++++++\n t/t5607-clone-bundle.sh | 12 ++++++++++++\n 10 files changed, 44 insertions(+), 13 deletions(-)\n\nRange-diff against v2:\n1:  4dae06d2dd = 1:  4dae06d2dd remote: allow `guess_remote_head()` to suppress advice\n2:  1180caabf1 ! 2:  2a69b881c4 builtin/clone: suppress unexpected default branch advice\n    @@ Commit message\n         Signed-off-by: Justin Tobler <jltobler@gmail.com>\n     \n      ## builtin/clone.c ##\n    +@@ builtin/clone.c: static struct ref *wanted_peer_refs(struct clone_opts *opts,\n    + \t\tif (head)\n    + \t\t\ttail_link_ref(head, &tail);\n    + \t\tif (option_single_branch)\n    +-\t\t\trefs = to_free = guess_remote_head(head, refs, 0);\n    ++\t\t\trefs = to_free =\n    ++\t\t\t\tguess_remote_head(head, refs,\n    ++\t\t\t\t\t\t  REMOTE_GUESS_HEAD_QUIET);\n    + \t} else if (option_single_branch) {\n    + \t\tlocal_refs = NULL;\n    + \t\ttail = &local_refs;\n     @@ builtin/clone.c: int cmd_clone(int argc,\n      \t}\n      \n    @@ t/t5607-clone-bundle.sh: test_expect_success 'git bundle v3 rejects unknown capa\n     +\tgit -C bundle-repo commit --allow-empty -m init &&\n     +\tgit -C bundle-repo bundle create repo.bundle --all &&\n     +\tGIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \\\n    -+\t\tgit clone bundle-repo/repo.bundle clone-repo 2>err &&\n    ++\t\tgit clone --single-branch bundle-repo/repo.bundle clone-repo 2>err &&\n     +\n     +\ttest_grep ! \"hint: \" err\n     +'\n3:  6fef1d070c = 3:  98b32cdc99 advice: allow disabling default branch name advice\n\nbase-commit: 683c54c999c301c2cd6f715c411407c413b1d84e\n-- \n2.49.0\n\n"},{"id":"514979","messageId":"20250325005148.1771502-2-jltobler@gmail.com","threadId":"63163","inReplyTo":"20250325005148.1771502-1-jltobler@gmail.com","subject":"[PATCH v3 1/3] remote: allow `guess_remote_head()` to suppress advice","fromName":"Justin Tobler","fromEmail":"jltobler@gmail.com","sentAt":"2025-03-25T00:51:46Z","receivedAt":"2025-03-25T00:55:34Z","isPatch":true,"sender":{"key":"jltobler@gmail.com","avatar":"https://avatars.githubusercontent.com/u/53454972?v=4"},"body":"The `repo_default_branch_name()` invoked through `guess_remote_head()`\nis configured to always display the default branch advice message.\n\nAdapt `guess_remote_head()` to accept flags and convert the `all`\nparameter to a flag. Add the `REMOTE_GUESS_HEAD_QUIET` flag to to enable\nsuppression of advice messages. Call sites are updated accordingly.\n\nSigned-off-by: Justin Tobler <jltobler@gmail.com>\n---\n builtin/fetch.c  |  2 +-\n builtin/remote.c |  2 +-\n remote.c         | 10 ++++++----\n remote.h         | 11 +++++++----\n 4 files changed, 15 insertions(+), 10 deletions(-)\n\ndiff --git a/builtin/fetch.c b/builtin/fetch.c\nindex 95fd0018b9..763314bfcb 100644\n--- a/builtin/fetch.c\n+++ b/builtin/fetch.c\n@@ -1638,7 +1638,7 @@ static int set_head(const struct ref *remote_refs, struct remote *remote)\n \n \tget_fetch_map(remote_refs, &refspec, &fetch_map_tail, 0);\n \tmatches = guess_remote_head(find_ref_by_name(remote_refs, \"HEAD\"),\n-\t\t\t\t    fetch_map, 1);\n+\t\t\t\t    fetch_map, REMOTE_GUESS_HEAD_ALL);\n \tfor (ref = matches; ref; ref = ref->next) {\n \t\tstring_list_append(&heads, strip_refshead(ref->name));\n \t}\ndiff --git a/builtin/remote.c b/builtin/remote.c\nindex 1b7aad8838..d2aeb5ba1f 100644\n--- a/builtin/remote.c\n+++ b/builtin/remote.c\n@@ -511,7 +511,7 @@ static int get_head_names(const struct ref *remote_refs, struct ref_states *stat\n \n \tget_fetch_map(remote_refs, &refspec, &fetch_map_tail, 0);\n \tmatches = guess_remote_head(find_ref_by_name(remote_refs, \"HEAD\"),\n-\t\t\t\t    fetch_map, 1);\n+\t\t\t\t    fetch_map, REMOTE_GUESS_HEAD_ALL);\n \tfor (ref = matches; ref; ref = ref->next)\n \t\tstring_list_append(&states->heads, abbrev_branch(ref->name));\n \ndiff --git a/remote.c b/remote.c\nindex e609cf5c56..1db88beaf3 100644\n--- a/remote.c\n+++ b/remote.c\n@@ -2297,7 +2297,7 @@ struct ref *get_local_heads(void)\n \n struct ref *guess_remote_head(const struct ref *head,\n \t\t\t      const struct ref *refs,\n-\t\t\t      int all)\n+\t\t\t      unsigned flags)\n {\n \tconst struct ref *r;\n \tstruct ref *list = NULL;\n@@ -2315,8 +2315,10 @@ struct ref *guess_remote_head(const struct ref *head,\n \t\treturn copy_ref(find_ref_by_name(refs, head->symref));\n \n \t/* If a remote branch exists with the default branch name, let's use it. */\n-\tif (!all) {\n-\t\tchar *default_branch = repo_default_branch_name(the_repository, 0);\n+\tif (!(flags & REMOTE_GUESS_HEAD_ALL)) {\n+\t\tchar *default_branch =\n+\t\t\trepo_default_branch_name(the_repository,\n+\t\t\t\t\t\t flags & REMOTE_GUESS_HEAD_QUIET);\n \t\tchar *ref = xstrfmt(\"refs/heads/%s\", default_branch);\n \n \t\tr = find_ref_by_name(refs, ref);\n@@ -2339,7 +2341,7 @@ struct ref *guess_remote_head(const struct ref *head,\n \t\t    oideq(&r->old_oid, &head->old_oid)) {\n \t\t\t*tail = copy_ref(r);\n \t\t\ttail = &((*tail)->next);\n-\t\t\tif (!all)\n+\t\t\tif (!(flags & REMOTE_GUESS_HEAD_ALL))\n \t\t\t\tbreak;\n \t\t}\n \t}\ndiff --git a/remote.h b/remote.h\nindex 6be5031f64..7e4943ae3a 100644\n--- a/remote.h\n+++ b/remote.h\n@@ -387,15 +387,18 @@ int format_tracking_info(struct branch *branch, struct strbuf *sb,\n \t\t\t int show_divergence_advice);\n \n struct ref *get_local_heads(void);\n+\n /*\n  * Find refs from a list which are likely to be pointed to by the given HEAD\n- * ref. If 'all' is false, returns the most likely ref; otherwise, returns a\n- * list of all candidate refs. If no match is found (or 'head' is NULL),\n- * returns NULL. All returns are newly allocated and should be freed.\n+ * ref. If REMOTE_GUESS_HEAD_ALL is set, return a list of all candidate refs;\n+ * otherwise, return the most likely ref. If no match is found (or 'head' is\n+ * NULL), returns NULL. All returns are newly allocated and should be freed.\n  */\n+#define REMOTE_GUESS_HEAD_ALL\t(1 << 0)\n+#define REMOTE_GUESS_HEAD_QUIET (1 << 1)\n struct ref *guess_remote_head(const struct ref *head,\n \t\t\t      const struct ref *refs,\n-\t\t\t      int all);\n+\t\t\t      unsigned flags);\n \n /* Return refs which no longer exist on remote */\n struct ref *get_stale_heads(struct refspec *rs, struct ref *fetch_map);\n-- \n2.49.0\n\n"},{"id":"514980","messageId":"20250325005148.1771502-3-jltobler@gmail.com","threadId":"63163","inReplyTo":"20250325005148.1771502-1-jltobler@gmail.com","subject":"[PATCH v3 2/3] builtin/clone: suppress unexpected default branch advice","fromName":"Justin Tobler","fromEmail":"jltobler@gmail.com","sentAt":"2025-03-25T00:51:47Z","receivedAt":"2025-03-25T00:55:35Z","isPatch":true,"sender":{"key":"jltobler@gmail.com","avatar":"https://avatars.githubusercontent.com/u/53454972?v=4"},"body":"In 199f44cb2ead (builtin/clone: allow remote helpers to detect repo,\n2024-02-27), clones started partially initializing the refdb before\nexecuting the remote helpers by creating a HEAD file and \"refs/\"\ndirectory. This has resulted in some scenarios where git-clone(1) now\nprints the default branch name advice message where it previously did\nnot.\n\nA side-effect of the HEAD file already existing, is that computation of\nthe default branch name is handled later in execution. This matters\nbecause prior to 97abaab5f6 (refs: drop `git_default_branch_name()`,\n2024-05-17), the default branch value would be computed during its first\nexecution and cached. Subsequent invocations would simply return the\ncached value. Since the next `git_default_branch_name()` call site,\nwhich is invoked through `guess_remote_head()`, is not configured to\nsuppress the advice message, computing the default branch name results\nin the advice message being printed.\n\nConfigure `guess_remote_head()` to suppress the advice message,\nrestoring the previous behavior.\n\nSigned-off-by: Justin Tobler <jltobler@gmail.com>\n---\n builtin/clone.c         |  7 +++++--\n t/t5607-clone-bundle.sh | 12 ++++++++++++\n 2 files changed, 17 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin/clone.c b/builtin/clone.c\nindex f14229abf4..baa76f88c3 100644\n--- a/builtin/clone.c\n+++ b/builtin/clone.c\n@@ -450,7 +450,9 @@ static struct ref *wanted_peer_refs(struct clone_opts *opts,\n \t\tif (head)\n \t\t\ttail_link_ref(head, &tail);\n \t\tif (option_single_branch)\n-\t\t\trefs = to_free = guess_remote_head(head, refs, 0);\n+\t\t\trefs = to_free =\n+\t\t\t\tguess_remote_head(head, refs,\n+\t\t\t\t\t\t  REMOTE_GUESS_HEAD_QUIET);\n \t} else if (option_single_branch) {\n \t\tlocal_refs = NULL;\n \t\ttail = &local_refs;\n@@ -1523,7 +1525,8 @@ int cmd_clone(int argc,\n \t}\n \n \tremote_head = find_ref_by_name(refs, \"HEAD\");\n-\tremote_head_points_at = guess_remote_head(remote_head, mapped_refs, 0);\n+\tremote_head_points_at = guess_remote_head(remote_head, mapped_refs,\n+\t\t\t\t\t\t  REMOTE_GUESS_HEAD_QUIET);\n \n \tif (option_branch) {\n \t\tour_head_points_at = find_remote_branch(mapped_refs, option_branch);\ndiff --git a/t/t5607-clone-bundle.sh b/t/t5607-clone-bundle.sh\nindex 82e3621ec5..d709bea753 100755\n--- a/t/t5607-clone-bundle.sh\n+++ b/t/t5607-clone-bundle.sh\n@@ -211,4 +211,16 @@ test_expect_success 'git bundle v3 rejects unknown capabilities' '\n \ttest_grep \"unknown capability .unknown=silly.\" output\n '\n \n+test_expect_success 'cloning bundle suppresses default branch name advice' '\n+\ttest_when_finished \"rm -rf bundle-repo clone-repo\" &&\n+\n+\tgit init bundle-repo &&\n+\tgit -C bundle-repo commit --allow-empty -m init &&\n+\tgit -C bundle-repo bundle create repo.bundle --all &&\n+\tGIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \\\n+\t\tgit clone --single-branch bundle-repo/repo.bundle clone-repo 2>err &&\n+\n+\ttest_grep ! \"hint: \" err\n+'\n+\n test_done\n-- \n2.49.0\n\n"},{"id":"514981","messageId":"20250325005148.1771502-4-jltobler@gmail.com","threadId":"63163","inReplyTo":"20250325005148.1771502-1-jltobler@gmail.com","subject":"[PATCH v3 3/3] advice: allow disabling default branch name advice","fromName":"Justin Tobler","fromEmail":"jltobler@gmail.com","sentAt":"2025-03-25T00:51:48Z","receivedAt":"2025-03-25T00:55:35Z","isPatch":true,"sender":{"key":"jltobler@gmail.com","avatar":"https://avatars.githubusercontent.com/u/53454972?v=4"},"body":"The default branch name advice message is displayed when\n`repo_default_branch_name()` is invoked and the `init.defaultBranch`\nconfig is not set. In this scenario, the advice message is always shown\neven if the `--no-advice` option is used.\n\nAdapt `repo_default_branch_name()` to allow the default branch name\nadvice message to be disabled with the `--no-advice` option and\ncorresponding configuration.\n\nSigned-off-by: Justin Tobler <jltobler@gmail.com>\n---\n advice.c        | 1 +\n advice.h        | 1 +\n refs.c          | 3 ++-\n t/t0001-init.sh | 8 ++++++++\n 4 files changed, 12 insertions(+), 1 deletion(-)\n\ndiff --git a/advice.c b/advice.c\nindex 1df43b7536..e5f0ff8449 100644\n--- a/advice.c\n+++ b/advice.c\n@@ -51,6 +51,7 @@ static struct {\n \t[ADVICE_AM_WORK_DIR] \t\t\t\t= { \"amWorkDir\" },\n \t[ADVICE_CHECKOUT_AMBIGUOUS_REMOTE_BRANCH_NAME] \t= { \"checkoutAmbiguousRemoteBranchName\" },\n \t[ADVICE_COMMIT_BEFORE_MERGE]\t\t\t= { \"commitBeforeMerge\" },\n+\t[ADVICE_DEFAULT_BRANCH_NAME]\t\t\t= { \"defaultBranchName\" },\n \t[ADVICE_DETACHED_HEAD]\t\t\t\t= { \"detachedHead\" },\n \t[ADVICE_DIVERGING]\t\t\t\t= { \"diverging\" },\n \t[ADVICE_FETCH_SET_HEAD_WARN]\t\t\t= { \"fetchRemoteHEADWarn\" },\ndiff --git a/advice.h b/advice.h\nindex d233cfc693..727dcecf4a 100644\n--- a/advice.h\n+++ b/advice.h\n@@ -18,6 +18,7 @@ enum advice_type {\n \tADVICE_AM_WORK_DIR,\n \tADVICE_CHECKOUT_AMBIGUOUS_REMOTE_BRANCH_NAME,\n \tADVICE_COMMIT_BEFORE_MERGE,\n+\tADVICE_DEFAULT_BRANCH_NAME,\n \tADVICE_DETACHED_HEAD,\n \tADVICE_DIVERGING,\n \tADVICE_FETCH_SET_HEAD_WARN,\ndiff --git a/refs.c b/refs.c\nindex 118465271d..bf9a40d6af 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -664,7 +664,8 @@ char *repo_default_branch_name(struct repository *r, int quiet)\n \tif (!ret) {\n \t\tret = xstrdup(\"master\");\n \t\tif (!quiet)\n-\t\t\tadvise(_(default_branch_name_advice), ret);\n+\t\t\tadvise_if_enabled(ADVICE_DEFAULT_BRANCH_NAME,\n+\t\t\t\t\t  _(default_branch_name_advice), ret);\n \t}\n \n \tfull_ref = xstrfmt(\"refs/heads/%s\", ret);\ndiff --git a/t/t0001-init.sh b/t/t0001-init.sh\nindex c49d9e0d38..f11a40811f 100755\n--- a/t/t0001-init.sh\n+++ b/t/t0001-init.sh\n@@ -830,6 +830,14 @@ test_expect_success 'advice on unconfigured init.defaultBranch' '\n \ttest_grep \"<YELLOW>hint: \" decoded\n '\n \n+test_expect_success 'advice on unconfigured init.defaultBranch disabled' '\n+\ttest_when_finished \"rm -rf no-advice\" &&\n+\n+\tGIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \\\n+\t\tgit -c advice.defaultBranchName=false init no-advice 2>err &&\n+\ttest_grep ! \"hint: \" err\n+'\n+\n test_expect_success 'overridden default main branch name (env)' '\n \ttest_config_global init.defaultBranch nmb &&\n \tGIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=env git init main-branch-env &&\n-- \n2.49.0\n\n"},{"id":"515023","messageId":"69ccc682-3f81-440f-8e96-a5af5d49fa60@gmail.com","threadId":"63163","inReplyTo":"20250325005148.1771502-1-jltobler@gmail.com","subject":"Re: [PATCH v3 0/3] clone: suppress unexpected advice message during clone","fromName":"Phillip Wood","fromEmail":"phillip.wood123@gmail.com","sentAt":"2025-03-25T14:35:40Z","receivedAt":"2025-03-25T14:35:45Z","isPatch":true,"sender":{"key":"phillip.wood@dunelm.org.uk","avatar":null},"body":"Hi Justin\n\nThe range-diff below looks good to me, Thanks for working on this\n\nPhillip\n\nOn 25/03/2025 00:51, Justin Tobler wrote:\n> Range-diff against v2:\n> 1:  4dae06d2dd = 1:  4dae06d2dd remote: allow `guess_remote_head()` to suppress advice\n> 2:  1180caabf1 ! 2:  2a69b881c4 builtin/clone: suppress unexpected default branch advice\n>      @@ Commit message\n>           Signed-off-by: Justin Tobler <jltobler@gmail.com>\n>       \n>        ## builtin/clone.c ##\n>      +@@ builtin/clone.c: static struct ref *wanted_peer_refs(struct clone_opts *opts,\n>      + \t\tif (head)\n>      + \t\t\ttail_link_ref(head, &tail);\n>      + \t\tif (option_single_branch)\n>      +-\t\t\trefs = to_free = guess_remote_head(head, refs, 0);\n>      ++\t\t\trefs = to_free =\n>      ++\t\t\t\tguess_remote_head(head, refs,\n>      ++\t\t\t\t\t\t  REMOTE_GUESS_HEAD_QUIET);\n>      + \t} else if (option_single_branch) {\n>      + \t\tlocal_refs = NULL;\n>      + \t\ttail = &local_refs;\n>       @@ builtin/clone.c: int cmd_clone(int argc,\n>        \t}\n>        \n>      @@ t/t5607-clone-bundle.sh: test_expect_success 'git bundle v3 rejects unknown capa\n>       +\tgit -C bundle-repo commit --allow-empty -m init &&\n>       +\tgit -C bundle-repo bundle create repo.bundle --all &&\n>       +\tGIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \\\n>      -+\t\tgit clone bundle-repo/repo.bundle clone-repo 2>err &&\n>      ++\t\tgit clone --single-branch bundle-repo/repo.bundle clone-repo 2>err &&\n>       +\n>       +\ttest_grep ! \"hint: \" err\n>       +'\n> 3:  6fef1d070c = 3:  98b32cdc99 advice: allow disabling default branch name advice\n> \n> base-commit: 683c54c999c301c2cd6f715c411407c413b1d84e\n\n"}]}