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

Re: bug: git shows hints that should be suppressed

From
Justin Tobler <jltobler@gmail.com>
Date
Mar 20, 2025, 01:36 UTC
Message-ID
<fff634dh5qeb4rgjqn7cru7v4a2voj4us4thvwtttxjcdnu2bu@jvv3htcon2ul>
In-Reply-To
<CABPp-BGTrEfGqX=o3W5rfqZiRdEuAzdKJuT8W0J=6kSY9ME4LQ@mail.gmail.com>
On 25/03/19 07:45AM, Elijah Newren wrote:
Show 22 quoted lines
> On Wed, Mar 19, 2025 at 2:59 AM <alan@norbauer.com> wrote:
> >
> > Thank you for filling out a Git bug report!
> > Please answer the following questions to help us understand your issue.
> >
> > What did you do before the bug happened? (Steps to reproduce your issue)
> > `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 .`
> >
> > What did you expect to happen? (Expected behavior)
> > 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.
> >
> > What happened instead? (Actual behavior)
> > 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).
> >
> > What's different between what you expected and what actually happened?
> > The hint on stderr was displayed.
> >
> > Anything else you want to add:
> > 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.
> 
> Bisects to 199f44cb2ead (builtin/clone: allow remote helpers to detect
> repo, 2024-02-27); cc'ing its author.

It looks like prior to 199f44cb2ead (builtin/clone: allow remote helpers to detect repo, 2024-02-27), the default branch name advice message would never be printed when cloning from a bundle regardless of whether `--quiet` option was set. This particual advice message also doesn't respect `GIT_ADVICE` either. So something about the change has made the message start printing when it previously did not.

Digging a bit further, this change started partially initializing the refdb with a HEAD file which had a side-effect of changing the location where the first `git_default_branch_name()` was invoked. This matters because `git_default_branch_name()` only computes the default branch name once and uses a cached value for subsequent invocations.

Previously, `create_reference_database()` was the first `git_default_branch_name()` call site and was configured to always suppress the advice message. Due to the refdb being partially initialized with a HEAD file, `create_reference_database()` stopped invoking `git_default_branch_name()` altogether and the default branch name computation was defferred to a subsequent potential call site `guess_remote_head()`. At this location, `git_default_branch_name()` is configured to not suppress advice messages.

Also, `guess_remote_head()` only invokes `git_default_branch_name()` in cases where the transport is unable to figure out the remote HEAD and must guess. This explains why the advice message gets printed for bundle clones, but not all clones.

One option to fix this would be to adapt `guess_remote_head()` to support configuring the underlying `git_default_branch_name()`, which has since been renamed to `repo_default_branch_name()`, to be quiet and suppress the advice message. The call site in clone could then be updated accordingly.

I'll submit a patch that does this.
-Justin
Previous: Elijah NewrenNext: Justin Tobler
Message 4 of 32 in “bug: git shows hints that should be suppressed”
  1. alan@norbauer.comMar 19, 2025
  2. alan@norbauer.comMar 19, 2025
  3. Elijah NewrenMar 19, 2025
  4. Justin ToblerMar 20, 2025
  5. 0/2 clone: suppress unexpected advice message during cloneJustin Tobler, Mar 20, 2025
  6. 1/2 remote: allow `guess_remote_head()` to suppress adviceJustin Tobler, Mar 20, 2025
  7. Patrick SteinhardtMar 20, 2025
  8. Justin ToblerMar 20, 2025
  9. Junio C HamanoMar 21, 2025
  10. 2/2 clone: suppress unexpected default branch adviceJustin Tobler, Mar 20, 2025
  11. Patrick SteinhardtMar 20, 2025
  12. Justin ToblerMar 20, 2025
  13. Phillip WoodMar 20, 2025
  14. Justin ToblerMar 20, 2025
  15. Phillip WoodMar 21, 2025
  16. 0/3 clone: suppress unexpected advice message during cloneJustin Tobler, Mar 21, 2025
  17. 1/3 remote: allow `guess_remote_head()` to suppress adviceJustin Tobler, Mar 21, 2025
  18. Phillip WoodMar 24, 2025
  19. Justin ToblerMar 24, 2025
  20. phillip.wood123@gmail.comMar 24, 2025
  21. 2/3 builtin/clone: suppress unexpected default branch adviceJustin Tobler, Mar 21, 2025
  22. Phillip WoodMar 24, 2025
  23. Justin ToblerMar 24, 2025
  24. 3/3 advice: allow disabling default branch name adviceJustin Tobler, Mar 21, 2025
  25. Phillip WoodMar 24, 2025
  26. Junio C HamanoMar 23, 2025
  27. 0/3 clone: suppress unexpected advice message during cloneJustin Tobler, Mar 25, 2025
  28. 1/3 remote: allow `guess_remote_head()` to suppress adviceJustin Tobler, Mar 25, 2025
  29. 2/3 builtin/clone: suppress unexpected default branch adviceJustin Tobler, Mar 25, 2025
  30. 3/3 advice: allow disabling default branch name adviceJustin Tobler, Mar 25, 2025
  31. Phillip WoodMar 25, 2025
  32. alan@norbauer.comMar 20, 2025

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

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