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 <hello@hidde.co>
This commit is contained in:
Hidde Beydals 2022-02-22 14:13:18 +01:00
parent 15c064abdf
commit eff40e22e9
1 changed files with 4 additions and 2 deletions

View File

@ -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)