Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

git/libgit2: fix failing tests when the default branch is not "master" #545

Merged
merged 1 commit into from
Jan 17, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion pkg/git/libgit2/checkout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -59,7 +71,7 @@ func TestCheckoutBranch_Checkout(t *testing.T) {
}{
{
name: "Default branch",
branch: "master",
branch: defaultBranch,
expectedCommit: secondCommit.String(),
},
{
Expand Down