@ -20,6 +20,7 @@ import (
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util"
"github.com/hashicorp/go-version"
)
@ -167,6 +168,47 @@ func InitSimple(ctx context.Context) error {
var initOnce sync . Once
func initFixGitHome117rc ( ) error {
// 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.
// remove the auto generated git config file (it will be moved to new home)
gitConfigNewPath := filepath . Join ( HomeDir ( ) , ".gitconfig" )
gitConfigLegacyPath := filepath . Join ( setting . RepoRootPath , ".gitconfig" )
if ok , err := util . IsExist ( gitConfigLegacyPath ) ; ok && err == nil {
if err = os . MkdirAll ( HomeDir ( ) , os . ModePerm ) ; err != nil {
return err
}
if ok , err = util . IsExist ( gitConfigNewPath ) ; ! ok && err == nil {
err = util . CopyFile ( gitConfigLegacyPath , gitConfigNewPath )
} else {
err = util . CopyFile ( gitConfigLegacyPath , gitConfigNewPath + ".bak" )
}
if err != nil {
return err
}
_ = os . Remove ( gitConfigLegacyPath )
}
// remove the empty directories, if some directories are non-empty, warn users and exit
var hasCheckErr bool
for _ , wellDirName := range [ ] string { ".ssh" , ".gnupg" } {
checkLegacyDir := filepath . Join ( setting . RepoRootPath , wellDirName )
_ = os . Remove ( checkLegacyDir ) // try to remove the empty dummy directory first
_ , checkErr := os . Stat ( checkLegacyDir ) // if the directory is not empty, then it won't be removed, it should be handled manually
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 ` , checkLegacyDir )
hasCheckErr = true
}
}
if hasCheckErr {
log . Fatal ( "Please fix errors above, remove legacy files." )
}
return nil
}
// InitOnceWithSync initializes git module with version check and change global variables, sync gitconfig.
// This method will update the global variables ONLY ONCE (just like git.CheckLFSVersion -- which is not ideal too),
// otherwise there will be data-race problem at the moment.
@ -176,28 +218,12 @@ func InitOnceWithSync(ctx context.Context) (err error) {
}
initOnce . Do ( func ( ) {
err = InitSimple ( ctx )
if err != nil {
if err = InitSimple ( ctx ) ; err != nil {
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" )
if err = initFixGitHome117rc ( ) ; err != nil {
return
}
// 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 {