Skip to content

Commit f68f880

Browse files
committed
[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 go-gitea#2333.
1 parent 91d4075 commit f68f880

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

modules/git/git.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ var (
3333
// DefaultContext is the default context to run git commands in, must be initialized by git.InitXxx
3434
DefaultContext context.Context
3535

36-
SupportProcReceive bool // >= 2.29
37-
SupportHashSha256 bool // >= 2.42, SHA-256 repositories no longer an ‘experimental curiosity’
36+
SupportProcReceive bool // >= 2.29
37+
SupportHashSha256 bool // >= 2.42, SHA-256 repositories no longer an ‘experimental curiosity’
38+
InvertedGitFlushEnv bool // 2.43.1
3839

3940
gitVersion *version.Version
4041
)
@@ -192,6 +193,8 @@ func InitFull(ctx context.Context) (err error) {
192193
log.Warn("sha256 hash support is disabled - requires Git >= 2.42. Gogit is currently unsupported")
193194
}
194195

196+
InvertedGitFlushEnv = CheckGitVersionEqual("2.43.1") == nil
197+
195198
if setting.LFS.StartServer {
196199
if CheckGitVersionAtLeast("2.1.2") != nil {
197200
return errors.New("LFS server support requires Git >= 2.1.2")
@@ -320,6 +323,21 @@ func CheckGitVersionAtLeast(atLeast string) error {
320323
return nil
321324
}
322325

326+
// CheckGitVersionEqual checks if the git version is equal to the constraint version.
327+
func CheckGitVersionEqual(equal string) error {
328+
if _, err := loadGitVersion(); err != nil {
329+
return err
330+
}
331+
atLeastVersion, err := version.NewVersion(equal)
332+
if err != nil {
333+
return err
334+
}
335+
if !gitVersion.Equal(atLeastVersion) {
336+
return fmt.Errorf("installed git binary version %s is not equal to %s", gitVersion.Original(), equal)
337+
}
338+
return nil
339+
}
340+
323341
func configSet(key, value string) error {
324342
stdout, _, err := NewCommand(DefaultContext, "config", "--global", "--get").AddDynamicArguments(key).RunStdString(nil)
325343
if err != nil && !err.IsExitCode(1) {

modules/git/repo_attribute.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,13 @@ func (c *CheckAttributeReader) Init(ctx context.Context) error {
133133
c.env = append(c.env, "GIT_WORK_TREE="+c.WorkTree)
134134
}
135135

136-
c.env = append(c.env, "GIT_FLUSH=1")
136+
// Version 2.43.1 has a bug where the behavior of `GIT_FLUSH` is flipped.
137+
// Ref: https://lore.kernel.org/git/CABn0oJvg3M_kBW-u=j3QhKnO=6QOzk-YFTgonYw_UvFS1NTX4g@mail.gmail.com
138+
if InvertedGitFlushEnv {
139+
c.env = append(c.env, "GIT_FLUSH=0")
140+
} else {
141+
c.env = append(c.env, "GIT_FLUSH=1")
142+
}
137143

138144
c.cmd.AddDynamicArguments(c.Attributes...)
139145

0 commit comments

Comments
 (0)