denoland/deno · error · anyhow::Error

`git {}` failed: {}

Error message

`git {}` failed: {}

What it means

git was spawned successfully but exited non-zero. The failing arguments and git's trimmed stderr are embedded in the message, so the underlying git failure — not a deno bug — explains the problem.

Source

Thrown at cli/util/git.rs:26

use tokio::process::Command;

/// Run `git` with `args` in `cwd`, returning stdout on success.
pub fn run_git(cwd: &Path, args: &[&str]) -> Result<String, AnyError> {
  let output = match std::process::Command::new("git")
    .current_dir(cwd)
    .args(args)
    .output()
  {
    Ok(output) => output,
    Err(err) => {
      return Err(anyhow!(
        "Failed to run `git {}`: {err}. Is git installed and on PATH?",
        args.join(" ")
      ));
    }
  };
  if !output.status.success() {
    return Err(anyhow!(
      "`git {}` failed: {}",
      args.join(" "),
      String::from_utf8_lossy(&output.stderr).trim()
    ));
  }
  Ok(String::from_utf8_lossy(&output.stdout).into_owned())
}

pub async fn check_if_git_repo_dirty(cwd: &Path) -> Option<String> {
  let bin_name = if cfg!(windows) { "git.exe" } else { "git" };

  //  Check if git exists
  let git_exists = Command::new(bin_name)
    .arg("--version")
    .stderr(Stdio::null())
    .stdout(Stdio::null())
    .status()
    .await

View on GitHub (pinned to 89f33cbef2)

Solutions

  1. Reproduce manually with the exact command shown in the message from the same directory — git's own stderr usually states the fix
  2. For 'not a git repository' errors: run from a repo root or initialize one with `git init`
  3. For network/auth failures: verify credentials and remote URLs, then retry once connectivity is restored

Example fix

# message: `git status --porcelain` failed: fatal: not a git repository
# before: run deno outside any repo
cd /tmp && deno release
# after
cd ~/myrepo && deno release
Defensive patterns

Strategy: try-catch

Validate before calling

# bash: verify the directory is a repo before git-dependent commands
git -C "$PWD" rev-parse --is-inside-work-tree >/dev/null 2>&1 || { echo "not a git repo" >&2; exit 1; }
deno release

Try / catch

# bash: surface git's stderr from deno's wrapper message
if ! deno release 2>err.log; then
  sed -n 's/^`git \([^`]*\)` failed: /git \1 failed: /p' err.log
  exit 1
fi

Prevention

When it happens

Trigger: Running git in a directory that is not a repository, referencing missing refs, credential/permission failures for remote operations, or any arguments git itself rejects.

Common situations: Workflows that check repo cleanliness in a non-repo directory; shallow clones missing an expected ref; auth failures in CI for fetch/clone operations.

Related errors


AI-assisted analysis of denoland/deno@89f33cbef2 (2026-08-16). Data as JSON: /api/errors/f3fe818e87a214da. Report an issue: GitHub.