rust-lang/rust · error · anyhow::Error

git command failed

Error message

git command failed

What it means

Thrown by init_submodule_if_needed when the spawned `git submodule update --init <path>` process exits with a non-zero status. citool calls this for src/llvm-project/ before running a job, to ensure the LLVM submodule is populated when the directory is empty.

Source

Thrown at src/ci/citool/src/utils.rs:53

/// Normalizes Windows-style path delimiters to Unix-style paths.
pub fn normalize_path_delimiters(name: &str) -> Cow<'_, str> {
    if name.contains("\\") { name.replace('\\', "/").into() } else { name.into() }
}

pub fn init_submodule_if_needed<P: AsRef<Path>>(path_to_submodule: P) -> anyhow::Result<()> {
    let path_to_submodule = path_to_submodule.as_ref();

    if let Ok(mut iter) = path_to_submodule.read_dir()
        && iter.any(|entry| entry.is_ok())
    {
        // Seems like the submodule is already initialized, nothing to be done here.
        return Ok(());
    }
    let mut child = Command::new("git")
        .args(&["submodule", "update", "--init"])
        .arg(path_to_submodule)
        .spawn()?;
    if !child.wait()?.success() { Err(anyhow::anyhow!("git command failed")) } else { Ok(()) }
}

View on GitHub (pinned to 7088e4b63a)

Solutions

  1. Run `git submodule update --init src/llvm-project/` manually to see git's own error output.
  2. Verify network connectivity and access to the LLVM repository URL in .gitmodules.
  3. If the submodule is already initialized, ensure the directory is non-empty so citool skips this step.
  4. Re-run `git submodule deinit -f src/llvm-project` then re-init if the local submodule state is corrupt.

Example fix

null
Defensive patterns

Strategy: try-catch

Validate before calling

// Skip the submodule init if the directory is already populated (citool already does this).
if path_to_submodule.read_dir().map(|mut d| d.next().is_some()).unwrap_or(false) {
    return Ok(());
}

Try / catch

if let Err(e) = init_submodule_if_needed("src/llvm-project/") {
    eprintln!("git submodule init failed: {e:#}");
    eprintln!("Run `git submodule update --init src/llvm-project/` manually to diagnose.");
    return Err(e);
}

Prevention

When it happens

Trigger: The submodule path is empty and git fails to clone it: network/git authentication error, missing network access, submodule URL changed in .gitmodules, or a corrupt local git index.

Common situations: Running citool in an environment without network egress to the LLVM git server; a shallow/partial clone whose .git/modules is inconsistent; .gitmodules points at an unreachable mirror; git credentials not configured for a private mirror.

Related errors


AI-assisted analysis of rust-lang/rust@7088e4b63a (2026-08-10). Data as JSON: /api/errors/6c4bf713328df002. Report an issue: GitHub.