Skip to content

Commit afa949f

Browse files
committed
fix
1 parent 4f386e2 commit afa949f

File tree

4 files changed

+13
-7
lines changed

4 files changed

+13
-7
lines changed

models/unittest/testdb.go

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

6161
setting.PasswordHashAlgo, _ = hash.SetDefaultPasswordHashAlgorithm("dummy")
62-
setting.InitGiteaEnvVars()
62+
setting.InitGiteaEnvVarsForTesting()
6363

6464
// Avoid loading the git's system config.
6565
// On macOS, system config sets the osxkeychain credential helper, which will cause tests to freeze with a dialog.

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 & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,6 @@ func (repo *Repository) CreateArchive(ctx context.Context, format ArchiveType, t
6363
cmd.AddOptionFormat("--format=%s", format.String())
6464
cmd.AddDynamicArguments(commitID)
6565

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-
6966
var stderr strings.Builder
7067
err := cmd.Run(&RunOpts{
7168
Dir: repo.Path,

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)