summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorGusted <postmaster@gusted.xyz>2024-02-13 09:03:22 +0100
committerGusted <postmaster@gusted.xyz>2024-02-13 18:33:18 +0100
commitf68f88097491746c6d4a36dc8f9631f764f65ef1 (patch)
treea3761c14322c97c6a8b99b6f9657adcee7df7dc6 /modules
parentMerge pull request '[FEAT] Don't log context cancelled SQL errors (squash)' (... (diff)
downloadforgejo-f68f88097491746c6d4a36dc8f9631f764f65ef1.tar.xz
forgejo-f68f88097491746c6d4a36dc8f9631f764f65ef1.zip
[BUG] Workaround borked Git version
- In Git version v2.43.1, the behavior of `GIT_FLUSH` was accidentially flipped. This causes Forgejo to hang on the `check-attr` command, because no output was being flushed. - Workaround this by detecting if Git v2.43.1 is used and set `GIT_FLUSH=0` thus getting the correct behavior. - Ref: https://lore.kernel.org/git/CABn0oJvg3M_kBW-u=j3QhKnO=6QOzk-YFTgonYw_UvFS1NTX4g@mail.gmail.com/ - Resolves #2333.
Diffstat (limited to 'modules')
-rw-r--r--modules/git/git.go22
-rw-r--r--modules/git/repo_attribute.go8
2 files changed, 27 insertions, 3 deletions
diff --git a/modules/git/git.go b/modules/git/git.go
index 89c23ff230..13a3127498 100644
--- a/modules/git/git.go
+++ b/modules/git/git.go
@@ -33,8 +33,9 @@ var (
// DefaultContext is the default context to run git commands in, must be initialized by git.InitXxx
DefaultContext context.Context
- SupportProcReceive bool // >= 2.29
- SupportHashSha256 bool // >= 2.42, SHA-256 repositories no longer an ‘experimental curiosity’
+ SupportProcReceive bool // >= 2.29
+ SupportHashSha256 bool // >= 2.42, SHA-256 repositories no longer an ‘experimental curiosity’
+ InvertedGitFlushEnv bool // 2.43.1
gitVersion *version.Version
)
@@ -192,6 +193,8 @@ func InitFull(ctx context.Context) (err error) {
log.Warn("sha256 hash support is disabled - requires Git >= 2.42. Gogit is currently unsupported")
}
+ InvertedGitFlushEnv = CheckGitVersionEqual("2.43.1") == nil
+
if setting.LFS.StartServer {
if CheckGitVersionAtLeast("2.1.2") != nil {
return errors.New("LFS server support requires Git >= 2.1.2")
@@ -320,6 +323,21 @@ func CheckGitVersionAtLeast(atLeast string) error {
return nil
}
+// CheckGitVersionEqual checks if the git version is equal to the constraint version.
+func CheckGitVersionEqual(equal string) error {
+ if _, err := loadGitVersion(); err != nil {
+ return err
+ }
+ atLeastVersion, err := version.NewVersion(equal)
+ if err != nil {
+ return err
+ }
+ if !gitVersion.Equal(atLeastVersion) {
+ return fmt.Errorf("installed git binary version %s is not equal to %s", gitVersion.Original(), equal)
+ }
+ return nil
+}
+
func configSet(key, value string) error {
stdout, _, err := NewCommand(DefaultContext, "config", "--global", "--get").AddDynamicArguments(key).RunStdString(nil)
if err != nil && !err.IsExitCode(1) {
diff --git a/modules/git/repo_attribute.go b/modules/git/repo_attribute.go
index 3c5a1429a9..3e09828ec5 100644
--- a/modules/git/repo_attribute.go
+++ b/modules/git/repo_attribute.go
@@ -133,7 +133,13 @@ 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")
+ // Version 2.43.1 has a bug where the behavior of `GIT_FLUSH` is flipped.
+ // Ref: https://lore.kernel.org/git/CABn0oJvg3M_kBW-u=j3QhKnO=6QOzk-YFTgonYw_UvFS1NTX4g@mail.gmail.com
+ if InvertedGitFlushEnv {
+ c.env = append(c.env, "GIT_FLUSH=0")
+ } else {
+ c.env = append(c.env, "GIT_FLUSH=1")
+ }
c.cmd.AddDynamicArguments(c.Attributes...)