Skip to content

Commit 3658eac

Browse files
committed
fix(git): fix feature branch collision
1 parent a68da60 commit 3658eac

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/internal/git/repository_test.go

+15-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,10 +49,15 @@ 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)
57+
5258
w, err := initRepo.Worktree()
5359
require.NoError(t, err)
60+
5461
filePath := "test.txt"
5562
newFile, err := fs.Create(filePath)
5663
require.NoError(t, err)
@@ -71,11 +78,18 @@ func TestRepository(t *testing.T) {
7178
URLs: []string{repoAddress},
7279
})
7380
require.NoError(t, err)
81+
t.Log(initRepo.Head())
7482
err = initRepo.Push(&git.PushOptions{
7583
RemoteName: "origin",
7684
})
7785
require.NoError(t, err)
7886

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

0 commit comments

Comments
 (0)