rust-lang/cargo · error
could not find `base-sha` for `{UPSTREAM_BRANCH}`, pass it i
Error message
could not find `base-sha` for `{UPSTREAM_BRANCH}`, pass it in directly What it means
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.
Source
Thrown at crates/xtask-bump-check/src/xtask.rs:276
Some(sha) => {
let obj = repo.revparse_single(sha)?;
obj.peel_to_commit()?
}
None => {
let upstream_branches = repo
.branches(Some(git2::BranchType::Remote))?
.filter_map(|r| r.ok())
.filter(|(b, _)| {
b.name()
.ok()
.flatten()
.unwrap_or_default()
.ends_with(&format!("/{UPSTREAM_BRANCH}"))
})
.map(|(b, _)| b)
.collect::<Vec<_>>();
if upstream_branches.is_empty() {
anyhow::bail!(
"could not find `base-sha` for `{UPSTREAM_BRANCH}`, pass it in directly"
);
}
let upstream_ref = upstream_branches[0].get();
if upstream_branches.len() > 1 {
let name = upstream_ref.name().expect("name is valid UTF-8");
let _ = gctx.shell().warn(format!(
"multiple `{UPSTREAM_BRANCH}` found, picking {name}"
));
}
upstream_ref.peel_to_commit()?
}
};
Ok(base_commit)
}
/// Returns `HEAD` of the Git repository if `head-rev` is missing.
fn get_head_commit<'a>(View on GitHub (pinned to eb98b54bc9)
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`.
Example fix
// before cargo bump-check // after cargo bump-check --base-sha $(git merge-base HEAD origin/main)
Defensive patterns
Strategy: validation
Validate before calling
// Ensure the upstream branch ref is present
let _ = Command::new("git").args(["fetch", "origin", UPSTREAM_BRANCH]).status();
// then run bump-check, or pass --base-sha explicitly Type guard
null
Try / catch
null
Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Detected changes in these crates but no version bump found:
- Could not find typos version in workflow
- The lints documentation is out-of-date. Run `cargo lint-docs
- argument for --color must be auto, always, or never, but fou
- can't checkout from '{}': you are in the offline mode ({offl
AI-assisted analysis of rust-lang/cargo@eb98b54bc9 (2026-08-11).
Data as JSON: /api/errors/803d25f9cac94efd.
Report an issue: GitHub.