Skip to content

Commit 5ebd1bc

Browse files
authored
fix(unit): resolve TestRepository host git configuration dependency (#3573)
Signed-off-by: Brandt Keller <[email protected]>
1 parent 340512c commit 5ebd1bc

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/internal/git/repository_test.go

+12-1
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ import (
77
"fmt"
88
"net/http"
99
"net/http/httptest"
10+
"os"
1011
"path/filepath"
1112
"testing"
1213

1314
"github.com/fluxcd/gitkit"
1415
"github.com/go-git/go-billy/v5/memfs"
1516
"github.com/go-git/go-git/v5"
1617
"github.com/go-git/go-git/v5/config"
18+
"github.com/go-git/go-git/v5/plumbing"
1719
"github.com/go-git/go-git/v5/plumbing/object"
1820
"github.com/go-git/go-git/v5/storage/memory"
1921
"github.com/stretchr/testify/require"
@@ -47,7 +49,10 @@ func TestRepository(t *testing.T) {
4749

4850
storer := memory.NewStorage()
4951
fs := memfs.New()
50-
initRepo, err := git.Init(storer, fs)
52+
options := git.InitOptions{
53+
DefaultBranch: plumbing.Main,
54+
}
55+
initRepo, err := git.InitWithOptions(storer, fs, options)
5156
require.NoError(t, err)
5257
w, err := initRepo.Worktree()
5358
require.NoError(t, err)
@@ -76,6 +81,12 @@ func TestRepository(t *testing.T) {
7681
})
7782
require.NoError(t, err)
7883

84+
// TODO: Is there a configuration that defines contents of HEAD that isn't read from ~/.gitconfig
85+
// Force-write refs/heads/main ref to HEAD to disk - Matching the above reference and decoupling from host gitconfig
86+
headFile := filepath.Join(cfg.Dir, "test.git", "HEAD")
87+
err = os.WriteFile(headFile, []byte("ref: refs/heads/main\n"), 0644)
88+
require.NoError(t, err, "Failed to write HEAD to disk")
89+
7990
repo, err := Clone(ctx, rootPath, repoAddress, false)
8091
require.NoError(t, err)
8192
require.Equal(t, filepath.Join(rootPath, expectedPath), repo.Path())

0 commit comments

Comments
 (0)