Skip to content

Commit

Permalink
add legacy file check
Browse files Browse the repository at this point in the history
  • Loading branch information
wxiaoguang committed Jun 27, 2022
1 parent 7f4b689 commit 780e858
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions modules/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"fmt"
"os"
"os/exec"
"path/filepath"
"regexp"
"runtime"
"strings"
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 780e858

Please sign in to comment.