{"record":{"id":"43b4154cfc2f0b04","repo":"golang/go","slug":"git-version-extraction-regexp-did-not-match-versio","errorCode":null,"errorMessage":"git version extraction regexp did not match version line: %q","messagePattern":"git version extraction regexp did not match version line: %q","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/cmd/go/internal/modfetch/codehost/git.go","lineNumber":1003,"sourceCode":"\t}\n\treturn RunWithArgs(ctx, args)\n}\n\n// Capture the major, minor and (optionally) patch version, but ignore anything later\nvar gitVersLineExtract = regexp.MustCompile(`git version\\s+(\\d+\\.\\d+(?:\\.\\d+)?)`)\n\nfunc gitVersion() (string, error) {\n\tgitOut, runErr := exec.Command(\"git\", \"version\").CombinedOutput()\n\tif runErr != nil {\n\t\treturn \"v0\", fmt.Errorf(\"failed to execute git version: %w\", runErr)\n\t}\n\treturn extractGitVersion(gitOut)\n}\n\nfunc extractGitVersion(gitOut []byte) (string, error) {\n\tmatches := gitVersLineExtract.FindSubmatch(gitOut)\n\tif len(matches) < 2 {\n\t\treturn \"v0\", fmt.Errorf(\"git version extraction regexp did not match version line: %q\", gitOut)\n\t}\n\treturn \"v\" + string(matches[1]), nil\n}\n\nfunc hasAtLeastGitVersion(minVers string) (bool, error) {\n\tgitVers, gitVersErr := gitVersion()\n\tif gitVersErr != nil {\n\t\treturn false, gitVersErr\n\t}\n\treturn semver.Compare(minVers, gitVers) <= 0, nil\n}\n\nconst minGitSHA256Vers = \"v2.29\"\n\nfunc gitSupportsSHA256() (bool, error) {\n\treturn hasAtLeastGitVersion(minGitSHA256Vers)\n}\n","sourceCodeStart":985,"sourceCodeEnd":1021,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/modfetch/codehost/git.go#L985-L1021","documentation":"gitVersion() ran successfully but the output did not match the regex `git version (\\d+\\.\\d+(\\.\\d+)?)`. extractGitVersion returns this error with the raw output quoted. Indicates git is present but emits a non-standard version banner.","triggerScenarios":"Custom git builds, wrappers named `git` that print a banner, git output redirected through a translator, or a git that prints a distribution prefix (e.g. some `git version 2.34.1.windows.1` variants are fine, but heavily modified banners are not).","commonSituations":"A shell alias or function named `git` shadowing the real binary; enterprise wrappers that prepend authentication notices; non-English locale forcing translation of the word 'version'; very old or very custom git forks.","solutions":["Run `git --version` manually and compare the literal first line against the expected pattern.","Remove any wrapper script or alias named `git` that decorates the output.","Force C locale for the go command: `LANG=C LC_ALL=C go build`.","Install a stock upstream git build to replace the customised one."],"exampleFix":"// before — wrapper prints 'MyCorp git shim\\ngit version 2.30'\n$ git version\n// error: git version extraction regexp did not match version line: \"MyCorp git shim\\ngit version 2.30\"\n\n// after — call real binary directly or remove shim","handlingStrategy":"validation","validationCode":"var gitVersLineExtract = regexp.MustCompile(`git version\\s+(\\d+\\.\\d+(?:\\.\\d+)?)`)\n\nfunc gitVersionParses() bool {\n    out, err := exec.Command(\"git\", \"version\").CombinedOutput()\n    if err != nil { return false }\n    return gitVersLineExtract.FindSubmatch(out) != nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Do not shadow `git` with aliases or wrapper scripts that decorate output.","Pin to a stock git build in CI; flag custom enterprise git shims for review.","Set LANG=C for the go command in environments that localise command output."],"tags":["git","regex","environment","version-detection"],"backgroundTag":null,"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T12:31:55.035Z"}