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

Re: [PATCH v3] var: add GIT_DEFAULT_BRANCH variable

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Nov 3, 2021, 19:57 UTC
Message-ID
<CAPig+cR0PL-XtfC8v4-u1Taq6yOLO=2HSHsNBnzvzLCyM-whZA@mail.gmail.com>
In-Reply-To
<20211103185331.599463-1-thomas@t-8ch.de>
On Wed, Nov 3, 2021 at 2:53 PM Thomas Weißschuh <thomas@t-8ch.de> wrote:
Show 15 quoted lines
> Introduce the logical variable GIT_DEFAULT_BRANCH which represents the
> the default branch name that will be used by "git init".
> [...]
> Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
> ---
> diff --git a/t/t0007-git-var.sh b/t/t0007-git-var.sh
> @@ -27,6 +27,25 @@ test_expect_success !FAIL_PREREQS,!AUTOIDENT 'requested identities are strict' '
> +test_expect_success 'get GIT_DEFAULT_BRANCH without configuration' '
> +       (
> +               sane_unset GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME &&
> +               echo master >expect &&
> +               git var GIT_DEFAULT_BRANCH >actual &&
> +               test_cmp expect actual
> +       )
> +'

So that we don't have to worry about this test breaking if the default branch ever is changed, would it make sense to stop hard-coding "master" here and instead employ the trick that Dscho mentioned earlier in the thread (i.e. create a dummy repo and ask it for its default branch)? Something like this (untested):

    (
        sane_unset GIT_TEST_... &&
        git init defbranch &&
        git -C defbranch symbolic-ref --short HEAD >expect &&
        git var GIT_DEFAULT_BRANCH >actual &&
        test_cmp expect actual
    )
Show 9 quoted lines
> +test_expect_success 'get GIT_DEFAULT_BRANCH with configuration' '
> +       test_config init.defaultbranch foo &&
> +       (
> +               sane_unset GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME &&
> +               echo foo >expect &&
> +               git var GIT_DEFAULT_BRANCH >actual &&
> +               test_cmp expect actual
> +       )
> +'
Previous: Thomas WeißschuhNext: Junio C Hamano
Message 13 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.