@@ -7,13 +7,15 @@ import (
7
7
"fmt"
8
8
"net/http"
9
9
"net/http/httptest"
10
+ "os"
10
11
"path/filepath"
11
12
"testing"
12
13
13
14
"github.com/fluxcd/gitkit"
14
15
"github.com/go-git/go-billy/v5/memfs"
15
16
"github.com/go-git/go-git/v5"
16
17
"github.com/go-git/go-git/v5/config"
18
+ "github.com/go-git/go-git/v5/plumbing"
17
19
"github.com/go-git/go-git/v5/plumbing/object"
18
20
"github.com/go-git/go-git/v5/storage/memory"
19
21
"github.com/stretchr/testify/require"
@@ -47,10 +49,15 @@ func TestRepository(t *testing.T) {
47
49
48
50
storer := memory .NewStorage ()
49
51
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 )
51
56
require .NoError (t , err )
57
+
52
58
w , err := initRepo .Worktree ()
53
59
require .NoError (t , err )
60
+
54
61
filePath := "test.txt"
55
62
newFile , err := fs .Create (filePath )
56
63
require .NoError (t , err )
@@ -71,11 +78,18 @@ func TestRepository(t *testing.T) {
71
78
URLs : []string {repoAddress },
72
79
})
73
80
require .NoError (t , err )
81
+ t .Log (initRepo .Head ())
74
82
err = initRepo .Push (& git.PushOptions {
75
83
RemoteName : "origin" ,
76
84
})
77
85
require .NoError (t , err )
78
86
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
+
79
93
repo , err := Clone (ctx , rootPath , repoAddress , false )
80
94
require .NoError (t , err )
81
95
require .Equal (t , filepath .Join (rootPath , expectedPath ), repo .Path ())
0 commit comments