Skip to content

Commit d7d0b9d

Browse files
committed
fix test
1 parent 2ee1456 commit d7d0b9d

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

modules/git/gitcmd/command_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,27 @@
44
package gitcmd
55

66
import (
7+
"fmt"
8+
"os"
79
"testing"
810

11+
"code.gitea.io/gitea/modules/setting"
12+
"code.gitea.io/gitea/modules/tempdir"
13+
914
"github.com/stretchr/testify/assert"
1015
)
1116

17+
func TestMain(m *testing.M) {
18+
gitHomePath, cleanup, err := tempdir.OsTempDir("gitea-test").MkdirTempRandom("git-home")
19+
if err != nil {
20+
_, _ = fmt.Fprintf(os.Stderr, "unable to create temp dir: %v", err)
21+
os.Exit(1)
22+
}
23+
defer cleanup()
24+
25+
setting.Git.HomePath = gitHomePath
26+
}
27+
1228
func TestRunWithContextStd(t *testing.T) {
1329
cmd := NewCommand("--version")
1430
stdout, stderr, err := cmd.RunStdString(t.Context(), &RunOpts{})

modules/git/gitcmd/env.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func HomeDir() string {
3232
if setting.Git.HomePath == "" {
3333
// strict check, make sure the git module is initialized correctly.
3434
// attention: when the git module is called in gitea sub-command (serv/hook), the log module might not obviously show messages to users/developers.
35-
// for example: if there is gitea git hook code calling cmd.NewCommand before git.InitXxx, the integration test won't show the real failure reasons.
35+
// for example: if there is gitea git hook code calling NewCommand before git.InitXxx, the integration test won't show the real failure reasons.
3636
log.Fatal("Unable to init Git's HomeDir, incorrect initialization of the setting and git modules")
3737
return ""
3838
}

0 commit comments

Comments
 (0)