{"record":{"id":"803d25f9cac94efd","repo":"rust-lang/cargo","slug":"could-not-find-base-sha-for-upstream-branch","errorCode":null,"errorMessage":"could not find `base-sha` for `{UPSTREAM_BRANCH}`, pass it in directly","messagePattern":"could not find `base-sha` for `(.+?)`, pass it in directly","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/xtask-bump-check/src/xtask.rs","lineNumber":276,"sourceCode":"        Some(sha) => {\n            let obj = repo.revparse_single(sha)?;\n            obj.peel_to_commit()?\n        }\n        None => {\n            let upstream_branches = repo\n                .branches(Some(git2::BranchType::Remote))?\n                .filter_map(|r| r.ok())\n                .filter(|(b, _)| {\n                    b.name()\n                        .ok()\n                        .flatten()\n                        .unwrap_or_default()\n                        .ends_with(&format!(\"/{UPSTREAM_BRANCH}\"))\n                })\n                .map(|(b, _)| b)\n                .collect::<Vec<_>>();\n            if upstream_branches.is_empty() {\n                anyhow::bail!(\n                    \"could not find `base-sha` for `{UPSTREAM_BRANCH}`, pass it in directly\"\n                );\n            }\n            let upstream_ref = upstream_branches[0].get();\n            if upstream_branches.len() > 1 {\n                let name = upstream_ref.name().expect(\"name is valid UTF-8\");\n                let _ = gctx.shell().warn(format!(\n                    \"multiple `{UPSTREAM_BRANCH}` found, picking {name}\"\n                ));\n            }\n            upstream_ref.peel_to_commit()?\n        }\n    };\n    Ok(base_commit)\n}\n\n/// Returns `HEAD` of the Git repository if `head-rev` is missing.\nfn get_head_commit<'a>(","sourceCodeStart":258,"sourceCodeEnd":294,"githubUrl":"https://github.com/rust-lang/cargo/blob/eb98b54bc9f3c74519f43d066cb3fd02ebc88df0/crates/xtask-bump-check/src/xtask.rs#L258-L294","documentation":"xtask-bump-check needs a base commit to diff against. When --base-sha is not provided, it looks for a remote branch named like the upstream branch (e.g. origin/main). If no such remote branch exists in the local git2 repository, it bails telling the user to pass --base-sha directly.","triggerScenarios":"Running `cargo bump-check` without --base-sha in a shallow clone, a fresh checkout without the upstream remote fetched, or a repo where the expected upstream branch (UPSTREAM_BRANCH constant) is absent.","commonSituations":"CI shallow clones (`depth: 1`) that lack the remote branch; local clones missing the 'origin/main' ref; renamed upstream branches; fork workflows where the upstream remote isn't configured.","solutions":["Pass --base-sha <commit> explicitly with the merge-base commit hash.","Fetch the upstream remote and branch: `git fetch origin main` (or the relevant upstream).","Ensure the clone is not shallow, or deepen it: `git fetch --unshallow`."],"exampleFix":"// before\ncargo bump-check\n// after\ncargo bump-check --base-sha $(git merge-base HEAD origin/main)","handlingStrategy":"validation","validationCode":"// Ensure the upstream branch ref is present\nlet _ = Command::new(\"git\").args([\"fetch\", \"origin\", UPSTREAM_BRANCH]).status();\n// then run bump-check, or pass --base-sha explicitly","typeGuard":"null","tryCatchPattern":"null","preventionTips":["Pass --base-sha explicitly in CI for deterministic diffs.","Fetch the upstream branch before running the check.","Avoid shallow clones in bump-check CI jobs."],"tags":["cargo","xtask","git","ci","clone"],"backgroundTag":null,"analyzedSha":"eb98b54bc9f3c74519f43d066cb3fd02ebc88df0","analyzedAt":"2026-08-11T17:42:36.556Z","contentChangedAt":"2026-08-11T17:42:36.556Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}