{"record":{"id":"25ff49a19971b989","repo":"rust-lang/cargo","slug":"unrecognized-git-version-output-stdout","errorCode":null,"errorMessage":"unrecognized `git --version` output: {stdout}","messagePattern":"unrecognized `git --version` output: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/sources/git/utils.rs","lineNumber":1175,"sourceCode":"    }\n\n    static CACHE: std::sync::OnceLock<Option<GitVersion>> = std::sync::OnceLock::new();\n    *CACHE.get_or_init(git_version)\n}\n\n#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]\n#[allow(unused)]\nstruct GitVersion {\n    major: usize,\n    minor: usize,\n    patch: usize,\n}\n\nimpl GitVersion {\n    fn from_version_stdout(stdout: &str) -> Result<Self, anyhow::Error> {\n        // See https://github.com/git/git/blob/f78ce2f7b6df702f93d40b85d6bda92a3f65da79/help.c#L779-L784\n        let Some(version) = stdout.strip_prefix(\"git version \") else {\n            anyhow::bail!(\"unrecognized `git --version` output: {stdout}\")\n        };\n        let (version, _) = version.split_once(\" \").unwrap_or((version, \"\"));\n        let (version, _) = version.split_once(\"\\n\").unwrap_or((version, \"\"));\n        version.parse()\n    }\n}\n\nimpl std::str::FromStr for GitVersion {\n    type Err = anyhow::Error;\n\n    fn from_str(version: &str) -> Result<Self, Self::Err> {\n        let unreleased = \"GIT\";\n\n        let s = version;\n        let (major, s) = s.split_once(\".\").unwrap_or((s, \"\"));\n        let mut major: usize = major.parse().map_err(|_err| {\n            anyhow::format_err!(\"unrecognized major version `{major}` in `{version}`\")\n        })?;","sourceCodeStart":1157,"sourceCodeEnd":1193,"githubUrl":"https://github.com/rust-lang/cargo/blob/42eee92bc9aa4449f4e25d84e4ceb1cf8e0f87f9/src/sources/git/utils.rs#L1157-L1193","documentation":"Cargo parses the output of `git --version` in `GitVersion::from_version_stdout` to determine the installed git version. If stdout does not start with the expected `git version ` prefix (matching git's own help.c format), the parse fails and this error is thrown. It means the `git` binary on PATH produced unexpected output — often not a real git, or a wrapper/shim emitting extra text.","triggerScenarios":"Running `git --version` returns stdout that does not begin with `git version ` (after any CLI/shell wrapping); e.g. a shim script, a git alias binary, or an environment where git prints a warning/banner before or instead of the version line.","commonSituations":"Developers with a `git` wrapper script (e.g. for credential handling) that rewrites output; Windows/MSYS environments where PATH resolves to a non-git stub; corporate sandbox wrappers; corrupted or replaced git installations.","solutions":["Run `git --version` manually and confirm output starts with `git version `; fix or remove any wrapper/shim shadowing the real git on PATH.","Reinstall or repair git so `git --version` prints the standard format (e.g. `git version 2.43.0`).","Check PATH for unexpected git entries (`which -a git`) and remove the offending one.","If using cargo's git CLI fetching, set `net.git-fetch-with-cli = false` to avoid the version check path where applicable."],"exampleFix":"// before: custom wrapper prints banner\n#!/bin/sh\necho \"ACME git wrapper\"\nexec /usr/bin/git \"$@\"\n// after: pass version query through untouched\n#!/bin/sh\nif [ \"$1\" = \"--version\" ]; then exec /usr/bin/git --version; fi\nexec /usr/bin/git \"$@\"","handlingStrategy":"validation","validationCode":"let out = std::process::Command::new(\"git\").arg(\"--version\").output()?;\nlet stdout = String::from_utf8_lossy(&out.stdout);\nif !stdout.starts_with(\"git version \") {\n    eprintln!(\"git on PATH is not a real git (output: {stdout:?}); fix PATH/reinstall git\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never wrap the git binary with scripts that alter `--version` output.","Audit PATH (`which -a git`) in CI images and dev containers for git shims.","Pin a known-good git installation in Docker images and verify `git --version` in a smoke test."],"tags":["git","version-parsing","environment"],"backgroundTag":"unexpected-response-shape","analyzedSha":"42eee92bc9aa4449f4e25d84e4ceb1cf8e0f87f9","analyzedAt":"2026-09-08T04:50:20.151Z","contentChangedAt":"2026-09-08T04:50:20.151Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}