@@ -20,6 +20,7 @@ import (
20
20
21
21
"code.gitea.io/gitea/modules/log"
22
22
"code.gitea.io/gitea/modules/setting"
23
+ "code.gitea.io/gitea/modules/util"
23
24
24
25
"github.com/hashicorp/go-version"
25
26
)
@@ -167,6 +168,47 @@ func InitSimple(ctx context.Context) error {
167
168
168
169
var initOnce sync.Once
169
170
171
+ func initFixGitHome117rc () error {
172
+ // Gitea 1.17-rc uses "setting.RepoRootPath" for Git HOME, which is incorrect.
173
+ // Do this check to make sure there is no legacy file in the RepoRootPath. This check might be able to be removed with 1.19 release.
174
+
175
+ // remove the auto generated git config file (it will be moved to new home)
176
+ gitConfigNewPath := filepath .Join (HomeDir (), ".gitconfig" )
177
+ gitConfigLegacyPath := filepath .Join (setting .RepoRootPath , ".gitconfig" )
178
+ if ok , err := util .IsExist (gitConfigLegacyPath ); ok && err == nil {
179
+ if err = os .MkdirAll (HomeDir (), os .ModePerm ); err != nil {
180
+ return err
181
+ }
182
+ if ok , err = util .IsExist (gitConfigNewPath ); ! ok && err == nil {
183
+ err = util .CopyFile (gitConfigLegacyPath , gitConfigNewPath )
184
+ } else {
185
+ err = util .CopyFile (gitConfigLegacyPath , gitConfigNewPath + ".bak" )
186
+ }
187
+ if err != nil {
188
+ return err
189
+ }
190
+ _ = os .Remove (gitConfigLegacyPath )
191
+ }
192
+
193
+ // remove the empty directories, if some directories are non-empty, warn users and exit
194
+ var hasCheckErr bool
195
+ for _ , wellDirName := range []string {".ssh" , ".gnupg" } {
196
+ checkLegacyDir := filepath .Join (setting .RepoRootPath , wellDirName )
197
+ _ = os .Remove (checkLegacyDir ) // try to remove the empty dummy directory first
198
+ _ , checkErr := os .Stat (checkLegacyDir ) // if the directory is not empty, then it won't be removed, it should be handled manually
199
+ if checkErr == nil || ! errors .Is (checkErr , os .ErrNotExist ) {
200
+ log .Error (`Git HOME has been moved to [git].HOME_PATH, but there are legacy file in old place. Please backup and remove the legacy files %q` , checkLegacyDir )
201
+ hasCheckErr = true
202
+ }
203
+ }
204
+
205
+ if hasCheckErr {
206
+ log .Fatal ("Please fix errors above, remove legacy files." )
207
+ }
208
+
209
+ return nil
210
+ }
211
+
170
212
// InitOnceWithSync initializes git module with version check and change global variables, sync gitconfig.
171
213
// This method will update the global variables ONLY ONCE (just like git.CheckLFSVersion -- which is not ideal too),
172
214
// otherwise there will be data-race problem at the moment.
@@ -176,28 +218,12 @@ func InitOnceWithSync(ctx context.Context) (err error) {
176
218
}
177
219
178
220
initOnce .Do (func () {
179
- err = InitSimple (ctx )
180
- if err != nil {
221
+ if err = InitSimple (ctx ); err != nil {
181
222
return
182
223
}
183
-
184
- // Gitea 1.17-rc uses "setting.RepoRootPath" for Git HOME, which is incorrect.
185
- // Do this check to make sure there is no legacy file in the RepoRootPath. This check might be able to be removed with 1.19 release.
186
- var hasCheckErr bool
187
- _ = os .Remove (filepath .Join (setting .RepoRootPath , ".gitconfig" )) // remove the auto generated git config file
188
- _ = os .Remove (filepath .Join (setting .RepoRootPath , ".ssh" )) // remove the empty dummy ".ssh" directory
189
- for _ , wellKnownName := range []string {".ssh" , ".gnupg" } {
190
- checkLegacyFile := filepath .Join (setting .RepoRootPath , wellKnownName )
191
- _ , checkErr := os .Stat (checkLegacyFile )
192
- if checkErr == nil || ! errors .Is (checkErr , os .ErrNotExist ) {
193
- log .Error (`Git HOME has been moved to [git].HOME_PATH, but there are legacy file in old place. Please backup and remove the legacy files %q` , checkLegacyFile )
194
- hasCheckErr = true
195
- }
196
- }
197
- if hasCheckErr {
198
- log .Fatal ("Please fix errors above, remove legacy files" )
224
+ if err = initFixGitHome117rc (); err != nil {
225
+ return
199
226
}
200
- // end of legacy Gitea 1.17-rc check
201
227
202
228
// Since git wire protocol has been released from git v2.18
203
229
if setting .Git .EnableAutoGitWireProtocol && CheckGitVersionAtLeast ("2.18" ) == nil {
0 commit comments