From eff40e22e9d3370fe15a4099bac3275243dd6502 Mon Sep 17 00:00:00 2001 From: Hidde Beydals Date: Tue, 22 Feb 2022 14:13:18 +0100 Subject: [PATCH] git/libgit2: assert proper test of default branch If there is no configuration set for `init.defaultBranch`, it does not return an error but an empty string. We now take this into account so we do not overwrite the default, and make the default `master` to match with libgit2 defaults. In addition, some comments have been added to not get confused about what commits we are checking against. Signed-off-by: Hidde Beydals --- pkg/git/libgit2/checkout_test.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pkg/git/libgit2/checkout_test.go b/pkg/git/libgit2/checkout_test.go index f648eae6..3f9e451d 100644 --- a/pkg/git/libgit2/checkout_test.go +++ b/pkg/git/libgit2/checkout_test.go @@ -51,8 +51,8 @@ func TestCheckoutBranch_Checkout(t *testing.T) { // ignores the error here because it can be defaulted // https://github.blog/2020-07-27-highlights-from-git-2-28/#introducing-init-defaultbranch - defaultBranch := "main" - if v, err := cfg.LookupString("init.defaultBranch"); err != nil { + defaultBranch := "master" + if v, err := cfg.LookupString("init.defaultBranch"); err != nil && v != "" { defaultBranch = v } @@ -61,10 +61,12 @@ func TestCheckoutBranch_Checkout(t *testing.T) { t.Fatal(err) } + // Branch off on first commit if err = createBranch(repo, "test", nil); err != nil { t.Fatal(err) } + // Create second commit on default branch secondCommit, err := commitFile(repo, "branch", "second", time.Now()) if err != nil { t.Fatal(err)