From 4029241b3b31a2314c2f40d590e4c60a9e4af961 Mon Sep 17 00:00:00 2001 From: Kevin McDermott Date: Mon, 17 Jan 2022 14:20:05 +0000 Subject: [PATCH] Don't assume master is the default branch. This introduces a quick lookup of the default branch rather than assuming "master". Signed-off-by: Kevin McDermott --- pkg/git/libgit2/checkout_test.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/pkg/git/libgit2/checkout_test.go b/pkg/git/libgit2/checkout_test.go index c24476094..0e82986d0 100644 --- a/pkg/git/libgit2/checkout_test.go +++ b/pkg/git/libgit2/checkout_test.go @@ -37,6 +37,18 @@ func TestCheckoutBranch_Checkout(t *testing.T) { defer repo.Free() defer os.RemoveAll(filepath.Join(repo.Path(), "..")) + cfg, err := git2go.OpenDefault() + if err != nil { + t.Fatal(err) + } + + // 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 = v + } + firstCommit, err := commitFile(repo, "branch", "init", time.Now()) if err != nil { t.Fatal(err) @@ -59,7 +71,7 @@ func TestCheckoutBranch_Checkout(t *testing.T) { }{ { name: "Default branch", - branch: "master", + branch: defaultBranch, expectedCommit: secondCommit.String(), }, {