Skip to content

Commit be57586

Browse files
authored
Merge pull request #545 from bigkevmcd/fix-failure-default-branch
2 parents 382e812 + 4029241 commit be57586

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

pkg/git/libgit2/checkout_test.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,18 @@ func TestCheckoutBranch_Checkout(t *testing.T) {
3737
defer repo.Free()
3838
defer os.RemoveAll(filepath.Join(repo.Path(), ".."))
3939

40+
cfg, err := git2go.OpenDefault()
41+
if err != nil {
42+
t.Fatal(err)
43+
}
44+
45+
// ignores the error here because it can be defaulted
46+
// https://github.blog/2020-07-27-highlights-from-git-2-28/#introducing-init-defaultbranch
47+
defaultBranch := "main"
48+
if v, err := cfg.LookupString("init.defaultBranch"); err != nil {
49+
defaultBranch = v
50+
}
51+
4052
firstCommit, err := commitFile(repo, "branch", "init", time.Now())
4153
if err != nil {
4254
t.Fatal(err)
@@ -59,7 +71,7 @@ func TestCheckoutBranch_Checkout(t *testing.T) {
5971
}{
6072
{
6173
name: "Default branch",
62-
branch: "master",
74+
branch: defaultBranch,
6375
expectedCommit: secondCommit.String(),
6476
},
6577
{

0 commit comments

Comments
 (0)