From 780e858d5c3155193d1a372466d083be8d917318 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Mon, 27 Jun 2022 11:27:10 +0800 Subject: [PATCH] add legacy file check --- modules/git/git.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/modules/git/git.go b/modules/git/git.go index c792a79886..2d373f44c8 100644 --- a/modules/git/git.go +++ b/modules/git/git.go @@ -11,6 +11,7 @@ import ( "fmt" "os" "os/exec" + "path/filepath" "regexp" "runtime" "strings" @@ -180,6 +181,24 @@ func InitOnceWithSync(ctx context.Context) (err error) { return } + // Gitea 1.17-rc uses "setting.RepoRootPath" for Git HOME, which is incorrect. + // 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. + var hasCheckErr bool + _ = os.Remove(filepath.Join(setting.RepoRootPath, ".gitconfig")) // remove the auto generated git config file + _ = os.Remove(filepath.Join(setting.RepoRootPath, ".ssh")) // remove the empty dummy ".ssh" directory + for _, wellKnownName := range []string{".ssh", ".gnupg"} { + checkLegacyFile := filepath.Join(setting.RepoRootPath, wellKnownName) + _, checkErr := os.Stat(checkLegacyFile) + if checkErr == nil || !errors.Is(checkErr, os.ErrNotExist) { + 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) + hasCheckErr = true + } + } + if hasCheckErr { + log.Fatal("Please fix errors above, remove legacy files") + } + // end of legacy Gitea 1.17-rc check + // Since git wire protocol has been released from git v2.18 if setting.Git.EnableAutoGitWireProtocol && CheckGitVersionAtLeast("2.18") == nil { globalCommandArgs = append(globalCommandArgs, "-c", "protocol.version=2")