fix: use clear error message when failed to parse git version (#39898) (#39903)

Backport #39898 by @wxiaoguang

fix  #39892

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
Giteabot
2026-10-21 04:35:32 +00:00
committed by GitHub
co-authored by wxiaoguang
parent 254e18107e
commit 7365946851
+7 -3
View File
@@ -71,12 +71,12 @@ func DefaultFeatures() *Features {
func loadGitVersionFeatures() (*Features, error) {
stdout, _, runErr := gitcmd.NewCommand("version").RunStdString(context.Background())
if runErr != nil {
return nil, runErr
return nil, fmt.Errorf(`failed to run command "git version": %w`, runErr)
}
ver, err := parseGitVersionLine(strings.TrimSpace(stdout))
if err != nil {
return nil, err
return nil, fmt.Errorf(`failed to parse output of command "git version": %w`, err)
}
features := &Features{gitVersion: ver, UsingGogit: isGogit}
@@ -108,7 +108,11 @@ func parseGitVersionLine(s string) (*version.Version, error) {
if len(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 {