mirror of
https://github.com/go-gitea/gitea.git
synced 2026-10-24 07:49:34 +02:00
fix: use clear error message when failed to parse git version (#39898)
fix #39892
This commit is contained in:
1 parent
82536a3ede
commit
76e88b30c0
1 file changed
+7
-3
+7
-3
@@ -68,12 +68,12 @@ func DefaultFeatures() *Features {
|
|||||||
func loadGitVersionFeatures() (*Features, error) {
|
func loadGitVersionFeatures() (*Features, error) {
|
||||||
stdout, _, runErr := gitcmd.NewCommand("version").RunStdString(context.Background())
|
stdout, _, runErr := gitcmd.NewCommand("version").RunStdString(context.Background())
|
||||||
if runErr != nil {
|
if runErr != nil {
|
||||||
return nil, runErr
|
return nil, fmt.Errorf(`failed to run command "git version": %w`, runErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
ver, err := parseGitVersionLine(strings.TrimSpace(stdout))
|
ver, err := parseGitVersionLine(strings.TrimSpace(stdout))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, fmt.Errorf(`failed to parse output of command "git version": %w`, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
features := &Features{gitVersion: ver}
|
features := &Features{gitVersion: ver}
|
||||||
@@ -104,7 +104,11 @@ func parseGitVersionLine(s string) (*version.Version, error) {
|
|||||||
if len(versionFields) > 3 {
|
if len(versionFields) > 3 {
|
||||||
versionFields = versionFields[:3]
|
versionFields = versionFields[:3]
|
||||||
}
|
}
|
||||||
return version.NewVersion(strings.Join(versionFields, "."))
|
ver, err := version.NewVersion(strings.Join(versionFields, "."))
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("invalid git version: %q: %w", s, err)
|
||||||
|
}
|
||||||
|
return ver, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkGitVersionCompatibility(gitVer *version.Version) error {
|
func checkGitVersionCompatibility(gitVer *version.Version) error {
|
||||||
|
|||||||
Reference in new issue
Block a user