zed-industries/zed · error

failed to fetch revision {rev} in directory {directory:?}

Error message

failed to fetch revision {rev} in directory {directory:?}

What it means

Raised in `checkout_repo` (crates/extension/src/extension_builder.rs:392) when `git checkout <rev>` fails and, while diagnosing that failure, the earlier shallow `git fetch --depth 1 origin <rev>` is found to have also failed. It means the builder could not download the requested revision of the grammar repository, so no checkout is possible. The checkout failure triggered the check, but the reported root cause is the failed fetch.

Source

Thrown at crates/extension/src/extension_builder.rs:392

        let fetch_output = util::command::new_command("git")
            .arg("--git-dir")
            .arg(&git_dir)
            .args(["fetch", "--depth", "1", "origin", rev])
            .output()
            .await
            .context("executing `git fetch`")?;

        let checkout_output = util::command::new_command("git")
            .arg("--git-dir")
            .arg(&git_dir)
            .args(["checkout", rev])
            .current_dir(directory)
            .output()
            .await
            .context("executing `git checkout`")?;
        if !checkout_output.status.success() {
            anyhow::ensure!(
                fetch_output.status.success(),
                "failed to fetch revision {rev} in directory {directory:?}"
            );
            anyhow::bail!(
                "failed to checkout revision {rev} in directory {directory:?}: {}",
                String::from_utf8_lossy(&checkout_output.stderr)
            );
        }

        Ok(())
    }

    async fn install_rust_wasm_target_if_needed(&self) -> Result<()> {
        let rustc_output = util::command::new_command("rustc")
            .args(["--print", "target-libdir", "--target", RUST_TARGET])
            .output()
            .await
            .context("running rustc")?;

View on GitHub (pinned to 9d272b0363)

Solutions

  1. Check network connectivity to the repo URL: `git ls-remote <url>` in a terminal; fix proxy/VPN/credentials as needed.
  2. Verify the pinned `rev` exists in the grammar repository (`git ls-remote --tags <url>`) and update the extension's grammar pin (the `version` field in grammar repositories) to a tag that exists.
  3. Delete the grammar directory to clear any half-fetched state (`rm -rf <directory>`) and rebuild.
  4. If the repo moved, update the `repository`/URL the extension points to, or fork it and pin to your fork.

Example fix

// before (grammars/tree-sitter-yaml/repository config in extension.toml or grammar pin)
[grammars.tree-sitter-yaml]
repository = "https://github.com/tree-sitter/tree-sitter-yaml"
commit = "v9.9.9"   // tag does not exist upstream

// after
[grammars.tree-sitter-yaml]
repository = "https://github.com/tree-sitter/tree-sitter-yaml"
commit = "v0.13.0"  // an existing tag
Defensive patterns

Strategy: retry

Validate before calling

// Verify the pinned revision exists and is reachable before building
const { execSync } = require('child_process');
function checkRev(url, rev) {
  const out = execSync(`git ls-remote ${url} ${rev}`, { encoding: 'utf8' });
  if (!out.trim()) throw new Error(`revision ${rev} not found in ${url}`);
}

Try / catch

try {
  await buildExtension(path);
} catch (err) {
  if (String(err).includes("failed to fetch revision")) {
    console.error("Network or bad rev pin. Check connectivity and that the tag exists upstream.", err.message);
  }
  throw err;
}

Prevention

When it happens

Trigger: Calling `compile_grammar` -> `checkout_repo` where `git checkout <rev>` exits non-zero AND `git fetch --depth 1 origin <rev>` also exited non-zero. Typical fetch failures: the `rev` (usually a tag like `v0.20.4`) does not exist upstream or is not a commit/branch/tag name; the repository URL is unreachable (network outage, proxy/firewall, DNS failure, GitHub downtime); authentication is required (private repo over ssh/https without credentials).

Common situations: An extension pins a grammar tag that was deleted or renamed upstream; developing an extension offline or behind a corporate proxy; the grammar repo moved and the pinned URL redirects away; rate-limiting or SSH key misconfiguration when fetching.

Understand the failure class

Background: "git command failed": what it means when a tool shells out to git and git exits non-zero — this error's family across 21 libraries.

Related errors


AI-assisted analysis of zed-industries/zed@9d272b0363 (2026-09-12). Data as JSON: /api/errors/ef8893cf95ee9df4. Report an issue: GitHub.