Skip to content

Commit f7192ab

Browse files
committed
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 <[email protected]>
1 parent e24e4da commit f7192ab

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

pkg/git/libgit2/checkout_test.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ func TestCheckoutBranch_Checkout(t *testing.T) {
5151

5252
// ignores the error here because it can be defaulted
5353
// https://github.blog/2020-07-27-highlights-from-git-2-28/#introducing-init-defaultbranch
54-
defaultBranch := "main"
55-
if v, err := cfg.LookupString("init.defaultBranch"); err != nil {
54+
defaultBranch := "master"
55+
if v, err := cfg.LookupString("init.defaultBranch"); err != nil && v != "" {
5656
defaultBranch = v
5757
}
5858

@@ -61,10 +61,12 @@ func TestCheckoutBranch_Checkout(t *testing.T) {
6161
t.Fatal(err)
6262
}
6363

64+
// Branch off on first commit
6465
if err = createBranch(repo, "test", nil); err != nil {
6566
t.Fatal(err)
6667
}
6768

69+
// Create second commit on default branch
6870
secondCommit, err := commitFile(repo, "branch", "second", time.Now())
6971
if err != nil {
7072
t.Fatal(err)

0 commit comments

Comments
 (0)