Skip to content

Commit 0201e02

Browse files
committed
fix
1 parent 4f386e2 commit 0201e02

File tree

4 files changed

+13
-15
lines changed

4 files changed

+13
-15
lines changed

models/unittest/testdb.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,7 @@ func InitSettings() {
5959
_ = hash.Register("dummy", hash.NewDummyHasher)
6060

6161
setting.PasswordHashAlgo, _ = hash.SetDefaultPasswordHashAlgorithm("dummy")
62-
setting.InitGiteaEnvVars()
63-
64-
// Avoid loading the git's system config.
65-
// On macOS, system config sets the osxkeychain credential helper, which will cause tests to freeze with a dialog.
66-
// But we do not set it in production at the moment, because it might be a "breaking" change,
67-
// more details are in "modules/git.commonBaseEnvs".
68-
_ = os.Setenv("GIT_CONFIG_NOSYSTEM", "true")
62+
setting.InitGiteaEnvVarsForTesting()
6963
}
7064

7165
// TestOptions represents test options

modules/git/command.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,10 +236,16 @@ type RunOpts struct {
236236
}
237237

238238
func commonBaseEnvs() []string {
239-
// at the moment, do not set "GIT_CONFIG_NOSYSTEM", users may have put some configs like "receive.certNonceSeed" in it
240239
envs := []string{
241-
"HOME=" + HomeDir(), // make Gitea use internal git config only, to prevent conflicts with user's git config
242-
"GIT_NO_REPLACE_OBJECTS=1", // ignore replace references (https://git-scm.com/docs/git-replace)
240+
// Make Gitea use internal git config only, to prevent conflicts with user's git config
241+
// It's better to use GIT_CONFIG_GLOBAL, but it requires git >= 2.32, so we still use HOME at the moment.
242+
"HOME=" + HomeDir(),
243+
// Avoid using system git config, it would cause problems (eg: use macOS osxkeychain to show a modal dialog, auto installing lfs hooks)
244+
// This might be a breaking change in 1.24, because some users said that they have put some configs like "receive.certNonceSeed" in "/etc/gitconfig"
245+
// For these users, they need to migrate the necessary configs to Gitea's git config file manually.
246+
"GIT_CONFIG_NOSYSTEM=1",
247+
// Ignore replace references (https://git-scm.com/docs/git-replace)
248+
"GIT_NO_REPLACE_OBJECTS=1",
243249
}
244250

245251
// some environment variables should be passed to git command

modules/git/repo_archive.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"context"
99
"fmt"
1010
"io"
11-
"os"
1211
"path/filepath"
1312
"strings"
1413
)
@@ -63,15 +62,11 @@ func (repo *Repository) CreateArchive(ctx context.Context, format ArchiveType, t
6362
cmd.AddOptionFormat("--format=%s", format.String())
6463
cmd.AddDynamicArguments(commitID)
6564

66-
// Avoid LFS hooks getting installed because of /etc/gitconfig, which can break pull requests.
67-
env := append(os.Environ(), "GIT_CONFIG_NOSYSTEM=1")
68-
6965
var stderr strings.Builder
7066
err := cmd.Run(&RunOpts{
7167
Dir: repo.Path,
7268
Stdout: target,
7369
Stderr: &stderr,
74-
Env: env,
7570
})
7671
if err != nil {
7772
return ConcatenateError(err, stderr.String())

modules/setting/config_env.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,10 @@ func InitGiteaEnvVars() {
177177
// But git would try "XDG_CONFIG_HOME/git/config" first if "HOME/.gitconfig" does not exist,
178178
// then our git.InitFull would still write to "XDG_CONFIG_HOME/git/config" if XDG_CONFIG_HOME is set.
179179
_ = os.Unsetenv("XDG_CONFIG_HOME")
180+
}
180181

182+
func InitGiteaEnvVarsForTesting() {
183+
InitGiteaEnvVars()
181184
_ = os.Unsetenv("GIT_AUTHOR_NAME")
182185
_ = os.Unsetenv("GIT_AUTHOR_EMAIL")
183186
_ = os.Unsetenv("GIT_AUTHOR_DATE")

0 commit comments

Comments
 (0)