{"record":{"id":"b19e7760fe7d63e2","repo":"zed-industries/zed","slug":"failed-to-run-git-init-in-directory-directory","errorCode":null,"errorMessage":"failed to run `git init` in directory {directory:?}","messagePattern":"failed to run `git init` in directory (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/extension/src/extension_builder.rs","lineNumber":357,"sourceCode":"                .args([\"remote\", \"get-url\", \"origin\"])\n                .env(\"GIT_CONFIG_GLOBAL\", \"/dev/null\")\n                .output()\n                .await?;\n            let has_remote = remotes_output.status.success()\n                && String::from_utf8_lossy(&remotes_output.stdout).trim() == url;\n            anyhow::ensure!(\n                has_remote,\n                \"grammar directory {directory:?} already exists, but is not a git clone of '{url}'\"\n            );\n        } else {\n            fs::create_dir_all(directory)\n                .with_context(|| format!(\"creating grammar directory {directory:?}\"))?;\n            let init_output = util::command::new_command(\"git\")\n                .arg(\"init\")\n                .current_dir(directory)\n                .output()\n                .await?;\n            anyhow::ensure!(\n                init_output.status.success(),\n                \"failed to run `git init` in directory {directory:?}\"\n            );\n\n            let remote_add_output = util::command::new_command(\"git\")\n                .arg(\"--git-dir\")\n                .arg(&git_dir)\n                .args([\"remote\", \"add\", \"origin\", url])\n                .output()\n                .await\n                .context(\"executing `git remote add`\")?;\n            anyhow::ensure!(\n                remote_add_output.status.success(),\n                \"failed to add remote {url} for git repository {git_dir:?}\"\n            );\n        }\n\n        let fetch_output = util::command::new_command(\"git\")","sourceCodeStart":339,"sourceCodeEnd":375,"githubUrl":"https://github.com/zed-industries/zed/blob/9d272b036335401f339d024ea94968fd51016c40/crates/extension/src/extension_builder.rs#L339-L375","documentation":"This error is raised in `checkout_repo` (crates/extension/src/extension_builder.rs:357) when Zed's extension builder runs `git init` to create a fresh git repository in the grammar's source directory and the command exits with a non-zero status. The builder initializes a repository so it can add the grammar's URL as an `origin` remote and shallow-fetch the pinned revision. The error means git itself failed before any network operation, so the checkout cannot proceed.","triggerScenarios":"Calling `compile_grammar` -> `checkout_repo` where the target grammar directory does not yet exist and `git init` (run with `current_dir(directory)`) exits non-zero. Specific conditions: the `git` binary is missing or not on PATH, `directory` points to something that is not a writable empty directory (e.g. permission denied, read-only filesystem), or an environment/config issue makes git refuse to initialize (e.g. GIT_CONFIG_GLOBAL pointing somewhere unusable).","commonSituations":"Building a Rust/WASM extension in a sandboxed CI environment without git installed; a stale or root-owned grammar cache directory left over from a previous run as a different user; running on a read-only filesystem or in a container whose home/workdir lacks write permissions; corporate security tooling blocking git execution.","solutions":["Verify git is installed and on PATH: run `git --version`; install it if missing (e.g. `apt install git` / `brew install git`).","Delete the broken grammar directory and rebuild so `git init` starts from a clean state: `rm -rf <extensions dir>/work/tree-sitter-<lang>` (or the directory named in the message).","Check the directory's ownership and permissions; ensure the user running Zed can write to it (`ls -ld <directory>`, `chown`/`chmod` as needed).","Ensure the filesystem containing the directory is writable and not mounted read-only."],"exampleFix":"// before (shell): building an extension in a minimal container without git\n$ zed --extensions-dir /opt/zed/extensions\n// error: failed to run `git init` in directory ...\n\n// after (shell): install git and clear the stale directory first\n$ apt-get update && apt-get install -y git\n$ rm -rf /opt/zed/extensions/work/tree-sitter-yaml\n$ zed --extensions-dir /opt/zed/extensions","handlingStrategy":"validation","validationCode":"// Before building, verify git exists and the grammar dir is writable-or-absent\nasync fn precheck(directory: &std::path::Path) -> Result<(), String> {\n    if which::which(\"git\").is_err() {\n        return Err(\"git is not installed or not on PATH\".into());\n    }\n    if directory.exists() && std::fs::metadata(directory).map(|m| m.permissions().readonly()).unwrap_or(true) {\n        return Err(format!(\"grammar directory {:?} is not writable\", directory));\n    }\n    Ok(())\n}","typeGuard":null,"tryCatchPattern":"// In Node/TS wrappers around the build, surface stderr and the directory\ntry {\n  await buildExtension(path);\n} catch (err) {\n  if (String(err).includes(\"failed to run `git init`\")) {\n    console.error(\"git is missing or the grammar directory is not writable:\", err.message);\n  }\n  throw err;\n}","preventionTips":["Install git in any environment (CI containers, Docker images) where you build extensions.","Run builds under the same user that owns the extension/work cache directory.","Periodically clear stale `work/` grammar directories after toolchain or user changes.","Confirm the cache/filesystem is not mounted read-only before building."],"tags":["git","environment","build","command-failed"],"backgroundTag":"git-command-failed","analyzedSha":"9d272b036335401f339d024ea94968fd51016c40","analyzedAt":"2026-09-12T19:35:53.743Z","contentChangedAt":"2026-09-12T19:35:53.743Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}