Skip to content

Commit 780e858

Browse files
committed
add legacy file check
1 parent 7f4b689 commit 780e858

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

modules/git/git.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"fmt"
1212
"os"
1313
"os/exec"
14+
"path/filepath"
1415
"regexp"
1516
"runtime"
1617
"strings"
@@ -180,6 +181,24 @@ func InitOnceWithSync(ctx context.Context) (err error) {
180181
return
181182
}
182183

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")
199+
}
200+
// end of legacy Gitea 1.17-rc check
201+
183202
// Since git wire protocol has been released from git v2.18
184203
if setting.Git.EnableAutoGitWireProtocol && CheckGitVersionAtLeast("2.18") == nil {
185204
globalCommandArgs = append(globalCommandArgs, "-c", "protocol.version=2")

0 commit comments

Comments
 (0)