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 > + ) > +'