{"record":{"id":"69c10fa375414259","repo":"zed-industries/zed","slug":"git-merge-base-failed-stderr","errorCode":null,"errorMessage":"git merge-base failed: {stderr}","messagePattern":"git merge-base failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/git/src/repository.rs","lineNumber":1969,"sourceCode":"                \"--\",\n            ]\n            .map(OsString::from)\n            .to_vec(),\n            DiffTreeType::Since { base, head } => [\n                \"diff-tree\",\n                \"-r\",\n                \"-z\",\n                \"--abbrev=64\",\n                \"--no-renames\",\n                base.as_str(),\n                head.as_str(),\n                \"--\",\n            ]\n            .map(OsString::from)\n            .to_vec(),\n        };\n\n        self.executor\n            .spawn(async move {\n                let git = git?;\n                let output = git.build_command(&args).output().await?;\n                if !output.status.success() {\n                    let stderr = String::from_utf8_lossy(&output.stderr);\n                    anyhow::bail!(\"git diff-tree failed: {stderr}\");\n                }\n\n                let stdout = String::from_utf8_lossy(&output.stdout);\n                let mut tree_diff = stdout.parse::<TreeDiff>()?;\n                let Some(merge_base_ref) = merge_base_ref else {\n                    return Ok(tree_diff);\n                };\n                let Some(working_directory) = working_directory else {\n                    return Ok(tree_diff);\n                };\n                if !tree_diff\n                    .entries","sourceCodeStart":1951,"sourceCodeEnd":1987,"githubUrl":"https://github.com/zed-industries/zed/blob/5a9b9558db01a6b906cec2fb70a797affdc58cdd/crates/git/src/repository.rs#L1951-L1987","documentation":"Error raised when the supplementary `git merge-base <ref> HEAD` invocation (used to compute the merge base while building a tree diff against a merge-base reference) exits with a non-zero status. The message carries the raw git stderr, which typically explains why the merge base could not be computed (e.g. bad revision, not a valid commit, repository corruption).","triggerScenarios":"`merge_base_ref` does not resolve (deleted remote branch or pruned tracking ref); HEAD and the base have no common ancestor (unrelated histories produce `fatal: Not a valid commit name` or no merge base); corrupt objects referenced by either ref.","commonSituations":"Comparing against a branch whose remote-tracking ref was pruned by `git fetch --prune`; forks with grafted or unrelated histories; comparing a branch against an upstream it never shared history with.","solutions":["Verify the ref still exists: `git rev-parse --verify <merge_base_ref>`, and fetch the remote to restore pruned tracking refs.","Handle unrelated histories upstream: skip the recreated-file comparison when no merge base exists.","Run `git merge-base <ref> HEAD` manually to see the exact stderr.","If both refs are valid but merge-base still fails, run `git fsck` to check for corrupt objects."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if git.run(&[\"rev-parse\", \"--verify\", \"--quiet\", &format!(\"{merge_base_ref}^{{commit}}\")]).await.is_err() {\n    // base ref is gone: skip the recreated-file comparison\n}","typeGuard":null,"tryCatchPattern":"match diff_result {\n    Err(e) if e.to_string().contains(\"merge-base failed\") => {\n        // ref pruned or unrelated histories: degrade to the plain tree diff\n    }\n    other => other?,\n}","preventionTips":["Fetch (with --prune) before comparing against remote-tracking refs.","Skip merge-base comparisons when histories are known to be unrelated.","Validate refs immediately before use; cached ref names go stale after upstream deletions."],"tags":["git","merge-base","subprocess","stderr"],"backgroundTag":"git-command-failed","analyzedSha":"5a9b9558db01a6b906cec2fb70a797affdc58cdd","analyzedAt":"2026-08-20T19:29:52.058Z","contentChangedAt":"2026-08-20T19:29:52.058Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}