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

Re: [PATCH] builtin: add git-default-branch command

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Oct 30, 2021, 17:18 UTC
Message-ID
<211030.86ilxe4edm.gmgdl@evledraar.gmail.com>
In-Reply-To
<20211030140112.834650-1-thomas@t-8ch.de>
On Sat, Oct 30 2021, Thomas Weißschuh wrote:
Show 11 quoted lines
> Introduce command `default-branch` which allows to retrieve the branch
> that will be used by git-init.
>
> Currently this command 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.

Recently there was a discussion on a similar topic, i.e. to have git explicitly aware of "default config" as far as "git config -l" etc. go:

    https://lore.kernel.org/git/87czvoowg2.fsf@evledraar.gmail.com/

I'd much rather see as add this as some mode of git-config, even if it's a new --get-or-git-default switch:

    git config --get-or-git-default init.defaultBranch

That would just currently die if you fed it any other value than init.defaultBranch, i.e. that (or similar) would be a generic enough interface that we could expand on it.

Whereas having a new-built in just for this one config variable...
Show 12 quoted lines
> +test_expect_success 'without configuration' '
> +	b=$(git default-branch) &&
> +	verbose test "$b" = master
> +'
> +
> +test_expect_success 'with configuration' '
> +	git config init.defaultbranch foo &&
> +	b=$(git default-branch) &&
> +	echo $b &&
> +	verbose test "$b" = foo
> +'
> +

Should lose the echo, and these comparisons should be using test_cmp, also use "test_config" not "git config" unless in a sub-repo or similar.

Previous: Thomas WeißschuhNext: Johannes Schindelin
Message 2 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.