Skip to content

Commit 7f4b689

Browse files
committed
Add git.HOME_PATH
1 parent 55a22d1 commit 7f4b689

File tree

7 files changed

+31
-13
lines changed

7 files changed

+31
-13
lines changed

custom/conf/app.example.ini

+4-1
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,10 @@ ROUTER = console
617617
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
618618
;;
619619
;; The path of git executable. If empty, Gitea searches through the PATH environment.
620-
PATH =
620+
;PATH =
621+
;;
622+
;; The HOME directory for Git
623+
;HOME_PATH = %(APP_DATA_PATH)/home
621624
;;
622625
;; Disables highlight of added and removed changes
623626
;DISABLE_DIFF_HIGHLIGHT = false

docs/content/doc/advanced/config-cheat-sheet.en-us.md

+1
Original file line numberDiff line numberDiff line change
@@ -947,6 +947,7 @@ Default templates for project boards:
947947
## Git (`git`)
948948

949949
- `PATH`: **""**: The path of Git executable. If empty, Gitea searches through the PATH environment.
950+
- `HOME_PATH`: **%(APP_DATA_PATH)/home**: The HOME directory for Git.
950951
- `DISABLE_DIFF_HIGHLIGHT`: **false**: Disables highlight of added and removed changes.
951952
- `MAX_GIT_DIFF_LINES`: **1000**: Max number of lines allowed of a single file in diff view.
952953
- `MAX_GIT_DIFF_LINE_CHARACTERS`: **5000**: Max character count per line highlighted in diff view.

docs/content/doc/advanced/signing.en-us.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,11 @@ repositories, `SIGNING_KEY=default` could be used to provide different
9797
signing keys on a per-repository basis. However, this is clearly not an
9898
ideal UI and therefore subject to change.
9999

100-
**Since 1.17**, Gitea runs git in its own home directory `[repository].ROOT` and uses its own config `{[repository].ROOT}/.gitconfig`.
100+
**Since 1.17**, Gitea runs git in its own home directory `[git].HOME_PATH` (default to `%(APP_DATA_PATH)/home`)
101+
and uses its own config `{[git].HOME_PATH}/.gitconfig`.
101102
If you have your own customized git config for Gitea, you should set these configs in system git config (aka `/etc/gitconfig`)
102-
or the Gitea internal git config `{[repository].ROOT}/.gitconfig`.
103-
Related home files for git command (like `.gnupg`) should also be put in Gitea's git home directory `[repository].ROOT`.
103+
or the Gitea internal git config `{[git].HOME_PATH}/.gitconfig`.
104+
Related home files for git command (like `.gnupg`) should also be put in Gitea's git home directory `[git].HOME_PATH`.
104105

105106

106107
### `INITIAL_COMMIT`

models/unittest/testdb.go

+2
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ func MainTest(m *testing.M, testOpts *TestOptions) {
107107

108108
setting.Packages.Storage.Path = filepath.Join(setting.AppDataPath, "packages")
109109

110+
setting.Git.HomePath = filepath.Join(setting.AppDataPath, "home")
111+
110112
if err = storage.Init(); err != nil {
111113
fatalTestError("storage.Init: %v\n", err)
112114
}

modules/git/git.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ func VersionInfo() string {
126126
}
127127

128128
func checkInit() error {
129-
if setting.RepoRootPath == "" {
130-
return errors.New("can not init Git's HomeDir (RepoRootPath is empty), the setting and git modules are not initialized correctly")
129+
if setting.Git.HomePath == "" {
130+
return errors.New("can not init Git's HomeDir, the setting and git modules are not initialized correctly")
131131
}
132132
if DefaultContext != nil {
133133
log.Warn("git module has been initialized already, duplicate init should be fixed")
@@ -137,14 +137,14 @@ func checkInit() error {
137137

138138
// HomeDir is the home dir for git to store the global config file used by Gitea internally
139139
func HomeDir() string {
140-
if setting.RepoRootPath == "" {
140+
if setting.Git.HomePath == "" {
141141
// strict check, make sure the git module is initialized correctly.
142142
// attention: when the git module is called in gitea sub-command (serv/hook), the log module is not able to show messages to users.
143143
// for example: if there is gitea git hook code calling git.NewCommand before git.InitXxx, the integration test won't show the real failure reasons.
144-
log.Fatal("can not get Git's HomeDir (RepoRootPath is empty), the setting and git modules are not initialized correctly")
144+
log.Fatal("can not get Git's HomeDir, the setting and git modules are not initialized correctly")
145145
return ""
146146
}
147-
return setting.RepoRootPath
147+
return setting.Git.HomePath
148148
}
149149

150150
// InitSimple initializes git module with a very simple step, no config changes, no global command arguments.
@@ -206,7 +206,7 @@ func InitOnceWithSync(ctx context.Context) (err error) {
206206
// syncGitConfig only modifies gitconfig, won't change global variables (otherwise there will be data-race problem)
207207
func syncGitConfig() (err error) {
208208
if err = os.MkdirAll(HomeDir(), os.ModePerm); err != nil {
209-
return fmt.Errorf("unable to create directory %s, err: %w", setting.RepoRootPath, err)
209+
return fmt.Errorf("unable to prepare git home directory %s, err: %w", HomeDir(), err)
210210
}
211211

212212
// Git requires setting user.name and user.email in order to commit changes - old comment: "if they're not set just add some defaults"

modules/git/git_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ import (
2121
func testRun(m *testing.M) error {
2222
_ = log.NewLogger(1000, "console", "console", `{"level":"trace","stacktracelevel":"NONE","stderr":true}`)
2323

24-
repoRootPath, err := os.MkdirTemp(os.TempDir(), "repos")
24+
gitHomePath, err := os.MkdirTemp(os.TempDir(), "git-home")
2525
if err != nil {
2626
return fmt.Errorf("unable to create temp dir: %w", err)
2727
}
28-
defer util.RemoveAll(repoRootPath)
29-
setting.RepoRootPath = repoRootPath
28+
defer util.RemoveAll(gitHomePath)
29+
setting.Git.HomePath = gitHomePath
3030

3131
if err = InitOnceWithSync(context.Background()); err != nil {
3232
return fmt.Errorf("failed to call Init: %w", err)

modules/setting/git.go

+11
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package setting
66

77
import (
8+
"path/filepath"
89
"time"
910

1011
"code.gitea.io/gitea/modules/log"
@@ -13,6 +14,7 @@ import (
1314
// Git settings
1415
var Git = struct {
1516
Path string
17+
HomePath string
1618
DisableDiffHighlight bool
1719
MaxGitDiffLines int
1820
MaxGitDiffLineCharacters int
@@ -67,7 +69,16 @@ var Git = struct {
6769
}
6870

6971
func newGit() {
72+
sec := Cfg.Section("git")
73+
7074
if err := Cfg.Section("git").MapTo(&Git); err != nil {
7175
log.Fatal("Failed to map Git settings: %v", err)
7276
}
77+
78+
Git.HomePath = sec.Key("HOME_PATH").MustString("home")
79+
if !filepath.IsAbs(Git.HomePath) {
80+
Git.HomePath = filepath.Join(AppDataPath, Git.HomePath)
81+
} else {
82+
Git.HomePath = filepath.Clean(Git.HomePath)
83+
}
7384
}

0 commit comments

Comments
 (0)