From 7365946851e9128f699ae3a7f40b518fbecc8bef Mon Sep 17 00:00:00 2001 From: Giteabot Date: Tue, 20 Oct 2026 21:35:32 -0700 Subject: [PATCH] fix: use clear error message when failed to parse git version (#39898) (#39903) Backport #39898 by @wxiaoguang fix #39892 Co-authored-by: wxiaoguang --- modules/git/git.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/modules/git/git.go b/modules/git/git.go index d2ab08061b4..a3c2a117d2d 100644 --- a/modules/git/git.go +++ b/modules/git/git.go @@ -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 {