Skip to content

Commit c858a19

Browse files
committed
improvements
1 parent 3d67efd commit c858a19

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

modules/gitrepo/main_test.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,31 @@
44
package gitrepo
55

66
import (
7+
"fmt"
78
"os"
89
"path/filepath"
910
"testing"
1011

1112
"code.gitea.io/gitea/modules/setting"
13+
"code.gitea.io/gitea/modules/util"
1214
)
1315

1416
const (
1517
testReposDir = "../git/tests/repos/"
1618
)
1719

1820
func TestMain(m *testing.M) {
21+
// since all test repository is defined by testReposDir, we need to set it here
22+
// So that all functions could work properly because Repository will only contain
23+
// Relative Path to RepoRootPath
1924
setting.RepoRootPath, _ = filepath.Abs(testReposDir)
20-
setting.Git.HomePath = filepath.Join(setting.RepoRootPath, ".home")
25+
// TODO: run command requires a home directory, we could set it to a temp dir
26+
gitHomePath, err := os.MkdirTemp(os.TempDir(), "git-home")
27+
if err != nil {
28+
panic(fmt.Errorf("unable to create temp dir: %w", err))
29+
}
30+
defer util.RemoveAll(gitHomePath)
31+
setting.Git.HomePath = gitHomePath
2132

2233
exitStatus := m.Run()
2334
os.Exit(exitStatus)

0 commit comments

Comments
 (0)