Skip to content

Commit

Permalink
git/libgit2: assert proper test of default branch
Browse files Browse the repository at this point in the history
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 <hello@hidde.co>
  • Loading branch information
hiddeco committed Feb 22, 2022
1 parent e24e4da commit f7192ab
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions pkg/git/libgit2/checkout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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)
Expand Down

0 comments on commit f7192ab

Please sign in to comment.