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

Re: [PATCH v2] var: add GIT_DEFAULT_BRANCH variable

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Nov 2, 2021, 19:14 UTC
Message-ID
<211102.868ry61hy3.gmgdl@evledraar.gmail.com>
In-Reply-To
<06095eb4-df18-4f23-8e72-26882c49f25c@t-8ch.de>
On Tue, Nov 02 2021, Thomas Weißschuh wrote:
Show 78 quoted lines
> On 2021-11-02 17:53+0100, Ævar Arnfjörð Bjarmason wrote:
>> On Tue, Nov 02 2021, Thomas Weißschuh wrote:
>> 
>> > Introduce the builtin variable GIT_DEFAULT_BRANCH which represents the
>> > the default branch name that will be used by git-init.
>> >
>> > Currently this variable is equivalent to
>> >     git config init.defaultbranch || 'master'
>> >
>> > This however will break if at one point the default branch is changed as
>> > indicated by `default_branch_name_advice` in `refs.c`.
>> >
>> > By providing this command ahead of time users of git can make their
>> > code forward-compatible.
>> >
>> > Co-developed-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
>> > Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
>> > ---
>> >
>> > Changes from v1 ( https://lore.kernel.org/git/20211030140112.834650-1-thomas@t-8ch.de/ ):
>> > * Replaced the custom subcommand with an internal variable
>> > * Cleaned up the tests
>> >
>> > @Johannes: I replaced BUG() with die() from your example because that seems to be
>> > nicer for user facing messages.
>> >
>> >  Documentation/git-var.txt |  3 +++
>> >  builtin/var.c             | 13 +++++++++++++
>> >  t/t0007-git-var.sh        | 19 +++++++++++++++++++
>> >  3 files changed, 35 insertions(+)
>> >
>> >  
>> > +static const char *default_branch(int flag)
>> > +{
>> > +	const char *name = repo_default_branch_name(the_repository, 1);
>> > +
>> > +	if (!name)
>> > +		die("could not determine the default branch name");
>> 
>> Isn't this die() unrechable given the similar logic in
>> repo_default_branch_name()? Hence the previous BUG(...)?
>
> Ok. Good point.
>
>> I really don't see how it makes sense to add this to "git var", we have
>> that to correspond to environment variables we use.
>> 
>> *Maybe* if we renamed GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME to
>> GIT_INITIAL_BRANCH_NAME and made it a non-test thing like
>> GIT_TEMPLATE_DIR, but even then shouldn't we be adding
>> "GIT_TEMPLATE_DIR" and any number of other things to this as well?
>> 
>> I'm not saying that your patch needs to do that, but we really should
>> think about the interface & future implications if we're going in this
>> direction.
>> 
>> The reason I suggested extending "git config" in [1] is because it seems
>> like a natural thing for "git config" to learn to spew out our idea of
>> default hardcoded config values to the user.
>> 
>> But creating a variable form of that existing config just so we can have
>> "git var" spew it out just seems weird.
>> 
>> We don't have or need such a variable now for anything else, so why go
>> through that indirection, instead of something that closes the feature
>> gap of asking what a config variable default is?
>> 
>> In any case whatever we do here this really should be updating the
>> documentation of init.defaultbranch & the relevant bits in the "git
>> init" manpage to add cross-references, similar to how we discuss
>> GIT_TEMPLATE_DIR now.
>>
>> 1. https://lore.kernel.org/git/211030.86ilxe4edm.gmgdl@evledraar.gmail.com/
>
> I'll then wait for a consensus of the git devs. The actual implementation
> shouldn't be the issue afterwards.
>
> Thanks for looking into this!

Please don't take that message as me or anyone else "pulling rank" just because we've got some previous commits in git.git. That applies to both me and Johannes, and clearly we disagree on this minor bit of UX direction.

I'd think if anything the opinion of someone who's not overly familiar with the system would be more valuable, i.e. yours, especially since you tried & failed to find a way to do this recently. Would you find it more intuitive to look in say "git var" over "git config" for this sort of information?

A further weirdness is that another effective source of config for this is the "unborn" ls-refs feature[1]. I'm not sure what that means for any query interface, i.e. would a user want to know what branch a freshly cloned repo would end up with in advance, taking into account all of the local config, remote "unborn" etc?

1. https://lore.kernel.org/git/878s8apthr.fsf@evledraar.gmail.com/
Previous: Thomas WeißschuhNext: Thomas Weißschuh
Message 7 of 18 in “builtin: add git-default-branch command”
  1. builtin: add git-default-branch commandThomas Weißschuh, Oct 30, 2021
  2. Ævar Arnfjörð BjarmasonOct 30, 2021
  3. Johannes SchindelinNov 2, 2021
  4. var: add GIT_DEFAULT_BRANCH variableThomas Weißschuh, Nov 2, 2021
  5. Ævar Arnfjörð BjarmasonNov 2, 2021
  6. Thomas WeißschuhNov 2, 2021
  7. Ævar Arnfjörð BjarmasonNov 2, 2021
  8. Thomas WeißschuhNov 2, 2021
  9. Jeff KingNov 3, 2021
  10. Eric SunshineNov 3, 2021
  11. Junio C HamanoNov 3, 2021
  12. var: add GIT_DEFAULT_BRANCH variableThomas Weißschuh, Nov 3, 2021
  13. Eric SunshineNov 3, 2021
  14. Junio C HamanoNov 3, 2021
  15. var: add GIT_DEFAULT_BRANCH variableThomas Weißschuh, Nov 3, 2021
  16. Junio C HamanoNov 3, 2021
  17. Junio C HamanoNov 3, 2021
  18. Johannes SchindelinNov 3, 2021

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.