1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-08 19:47:21 +00:00

Refactor git version functions and check compatibility (#29155) (#29157)

Backport #29155 with an extra change: tolerate the git 2.43.1 GIT_FLUSH
bug in Gitea 1.21.x, more details in the comment of repo_attribute.go

Manually tested with git 2.43.1 and an old git (2.39.2)
This commit is contained in:
wxiaoguang
2024-02-17 10:47:18 +08:00
committed by GitHub
parent 8cd83ff391
commit 906a722fca
3 changed files with 80 additions and 31 deletions

View File

@ -11,6 +11,8 @@ import (
"os"
"code.gitea.io/gitea/modules/log"
"github.com/hashicorp/go-version"
)
// CheckAttributeOpts represents the possible options to CheckAttribute
@ -133,7 +135,14 @@ func (c *CheckAttributeReader) Init(ctx context.Context) error {
c.env = append(c.env, "GIT_WORK_TREE="+c.WorkTree)
}
c.env = append(c.env, "GIT_FLUSH=1")
if gitVersion.Equal(version.Must(version.NewVersion("2.43.1"))) {
// https://github.com/go-gitea/gitea/issues/29141 gitea hanging with git 2.43.1 #29141
// https://lore.kernel.org/git/CABn0oJvg3M_kBW-u=j3QhKnO=6QOzk-YFTgonYw_UvFS1NTX4g@mail.gmail.com/
// git 2.43.1 has a bug: the GIT_FLUSH polarity is flipped
c.env = append(c.env, "GIT_FLUSH=0")
} else {
c.env = append(c.env, "GIT_FLUSH=1")
}
c.cmd.AddDynamicArguments(c.Attributes...)