Skip to content

Commit 509d811

Browse files
authored
Upgrade required git version to 2.0 (go-gitea#19577)
* Upgrade required git version to 2.0 * update document
1 parent 0ba3ada commit 509d811

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

docs/content/doc/installation/from-binary.en-us.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ Of note, configuring `GITEA_WORK_DIR` will tell Gitea where to base its working
5050

5151
### Prepare environment
5252

53-
Check that Git is installed on the server. If it is not, install it first.
53+
Check that Git is installed on the server. If it is not, install it first. Gitea requires Git version >= 2.0.
54+
5455
```sh
5556
git --version
5657
```

modules/git/git.go

+16-6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package git
88
import (
99
"context"
1010
"fmt"
11+
"os"
1112
"os/exec"
1213
"runtime"
1314
"strings"
@@ -20,10 +21,11 @@ import (
2021
)
2122

2223
var (
23-
// Prefix the log prefix
24-
Prefix = "[git-module] "
2524
// GitVersionRequired is the minimum Git version required
26-
GitVersionRequired = "1.7.2"
25+
// At the moment, all code for git 1.x are not changed, if some users want to test with old git client
26+
// or bypass the check, they still have a chance to edit this variable manually.
27+
// If everything works fine, the code for git 1.x could be removed in a separate PR before 1.17 frozen.
28+
GitVersionRequired = "2.0.0"
2729

2830
// GitExecutable is the command name of git
2931
// Could be updated to an absolute path while initialization
@@ -87,13 +89,13 @@ func SetExecutablePath(path string) error {
8789
}
8890
absPath, err := exec.LookPath(GitExecutable)
8991
if err != nil {
90-
return fmt.Errorf("Git not found: %v", err)
92+
return fmt.Errorf("git not found: %w", err)
9193
}
9294
GitExecutable = absPath
9395

9496
err = LoadGitVersion()
9597
if err != nil {
96-
return fmt.Errorf("Git version missing: %v", err)
98+
return fmt.Errorf("unable to load git version: %w", err)
9799
}
98100

99101
versionRequired, err := version.NewVersion(GitVersionRequired)
@@ -102,7 +104,15 @@ func SetExecutablePath(path string) error {
102104
}
103105

104106
if gitVersion.LessThan(versionRequired) {
105-
return fmt.Errorf("Git version not supported. Requires version > %v", GitVersionRequired)
107+
moreHint := "get git: https://git-scm.com/download/"
108+
if runtime.GOOS == "linux" {
109+
// there are a lot of CentOS/RHEL users using old git, so we add a special hint for them
110+
if _, err = os.Stat("/etc/redhat-release"); err == nil {
111+
// ius.io is the recommended official(git-scm.com) method to install git
112+
moreHint = "get git: https://git-scm.com/download/linux and https://ius.io"
113+
}
114+
}
115+
return fmt.Errorf("installed git version %q is not supported, Gitea requires git version >= %q, %s", gitVersion.Original(), GitVersionRequired, moreHint)
106116
}
107117

108118
return nil

0 commit comments

Comments
 (0)