From c7eb088dd2dd7bd61698db7dd912795c3383175d Mon Sep 17 00:00:00 2001 From: JonRB Date: Wed, 1 Jan 2025 02:32:36 +0000 Subject: [PATCH 1/3] unset XDG_HOME_CONFIG as gitea manages configuration locations adding error check to manage lint --- cmd/main.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cmd/main.go b/cmd/main.go index fd648946efa39..589124fae7a94 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -165,6 +165,11 @@ func NewMainApp(appVer AppVersion) *cli.App { app.Commands = append(app.Commands, subCmdWithConfig...) app.Commands = append(app.Commands, subCmdStandalone...) + err := os.Unsetenv("XDG_CONFIG_HOME") // unset if set as HOME is managed by gitea + if err != nil { + fmt.Printf("error unsetting XDG_CONFIG_HOME") + } + return app } From a0b8a3cb767295a956b9408f07291a65d52740df Mon Sep 17 00:00:00 2001 From: JonRB <4564448+eeyrjmr@users.noreply.github.com> Date: Wed, 1 Jan 2025 02:55:17 +0000 Subject: [PATCH 2/3] Update cmd/main.go Co-authored-by: wxiaoguang --- cmd/main.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/cmd/main.go b/cmd/main.go index 589124fae7a94..8847a77b2139d 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -165,11 +165,7 @@ func NewMainApp(appVer AppVersion) *cli.App { app.Commands = append(app.Commands, subCmdWithConfig...) app.Commands = append(app.Commands, subCmdStandalone...) - err := os.Unsetenv("XDG_CONFIG_HOME") // unset if set as HOME is managed by gitea - if err != nil { - fmt.Printf("error unsetting XDG_CONFIG_HOME") - } - + _ = os.Unsetenv("XDG_CONFIG_HOME") // unset if set as HOME is managed by gitea return app } From 0a27cf671b3a9ea12b00f386321ae930a048b1e3 Mon Sep 17 00:00:00 2001 From: JonRB Date: Wed, 1 Jan 2025 14:21:50 +0000 Subject: [PATCH 3/3] clearing/setting variables now a setting function for reuse --- cmd/main.go | 2 +- models/unittest/testdb.go | 1 + modules/setting/config_env.go | 5 +++++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/cmd/main.go b/cmd/main.go index 8847a77b2139d..7251bd09a3fe3 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -165,7 +165,7 @@ func NewMainApp(appVer AppVersion) *cli.App { app.Commands = append(app.Commands, subCmdWithConfig...) app.Commands = append(app.Commands, subCmdStandalone...) - _ = os.Unsetenv("XDG_CONFIG_HOME") // unset if set as HOME is managed by gitea + setting.InitGiteaEnvVars() return app } diff --git a/models/unittest/testdb.go b/models/unittest/testdb.go index 75044d19e8e44..43d084845ce6b 100644 --- a/models/unittest/testdb.go +++ b/models/unittest/testdb.go @@ -59,6 +59,7 @@ func InitSettings() { _ = hash.Register("dummy", hash.NewDummyHasher) setting.PasswordHashAlgo, _ = hash.SetDefaultPasswordHashAlgorithm("dummy") + setting.InitGiteaEnvVars() } // TestOptions represents test options diff --git a/modules/setting/config_env.go b/modules/setting/config_env.go index dfcb7db3c8624..f05e8a4d7bb35 100644 --- a/modules/setting/config_env.go +++ b/modules/setting/config_env.go @@ -166,3 +166,8 @@ func EnvironmentToConfig(cfg ConfigProvider, envs []string) (changed bool) { } return changed } + +// InitGiteaEnvVars initilises the environment for gitea +func InitGiteaEnvVars() { + _ = os.Unsetenv("XDG_CONFIG_HOME") // unset if set as HOME is managed by gitea +}