{"record":{"id":"5f9d5b8f73b0a88d","repo":"zed-industries/zed","slug":"failed-to-run-git-init-in-directory","errorCode":null,"errorMessage":"failed to run `git init` in directory '{}'","messagePattern":"failed to run `git init` in directory '(.+?)'","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/extension/src/extension_builder.rs","lineNumber":392,"sourceCode":"                && String::from_utf8_lossy(&remotes_output.stdout).trim() == url;\n            if !has_remote {\n                bail!(\n                    \"grammar directory '{}' already exists, but is not a git clone of '{}'\",\n                    directory.display(),\n                    url\n                );\n            }\n        } else {\n            fs::create_dir_all(directory).with_context(|| {\n                format!(\"failed to create grammar directory {}\", directory.display(),)\n            })?;\n            let init_output = util::command::new_command(\"git\")\n                .arg(\"init\")\n                .current_dir(directory)\n                .output()\n                .await?;\n            if !init_output.status.success() {\n                bail!(\n                    \"failed to run `git init` in directory '{}'\",\n                    directory.display()\n                );\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(\"failed to execute `git remote add`\")?;\n            if !remote_add_output.status.success() {\n                bail!(\n                    \"failed to add remote {url} for git repository {}\",\n                    git_dir.display()\n                );\n            }","sourceCodeStart":374,"sourceCodeEnd":410,"githubUrl":"https://github.com/zed-industries/zed/blob/f4178619acd0d47ea1f76a2025c42962c6d6638c/crates/extension/src/extension_builder.rs#L374-L410","documentation":"checkout_repo() creates the grammar directory and runs 'git init' inside it (after GIT_CONFIG_GLOBAL is neutralized only for later commands - this call inherits the environment). A non-zero exit from git init bails with this message. git init fails rarely: permissions, read-only filesystem, broken global config, or disk issues.","triggerScenarios":"The grammar cache directory was created (create_dir_all succeeded) but 'git init' inside it returned failure - e.g. the cache filesystem is read-only or full, the user lacks write permission, a global git config/template makes init fail, or a stale .git tail exists inside the new directory.","commonSituations":"Cache dir on a read-only or full volume; restrictive permissions on the extensions cache after a chown/reinstall; broken ~/.gitconfig or GIT_* environment variables injected by wrappers/containers that make every git invocation fail.","solutions":["Run 'git init' manually in the directory named by the message to see the real git error","Check the directory and cache-root permissions and disk space for the extension cache filesystem","Inspect ~/.gitconfig / GIT_* env for anything breaking git (test with GIT_CONFIG_GLOBAL=/dev/null git init)","If the directory is in a weird half-initialized state, delete it and rebuild so the builder recreates it cleanly"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Ensure the cache root is writable before building\nlet probe = cache_dir.join(\".write-probe\");\nstd::fs::write(&probe, b\"\").context(\"extension cache dir is not writable\")?;\nstd::fs::remove_file(&probe).ok();\nanyhow::ensure!(which::which(\"git\").is_ok(), \"git is required to build grammar extensions\");","typeGuard":null,"tryCatchPattern":"match build_result {\n    Err(err) if err.to_string().contains(\"git init\") =>\n        Err(err.context(\"cannot initialize git repo in the grammar cache - check permissions/disk\")),\n    rest => rest,\n}","preventionTips":["Keep the extensions cache on a writable local filesystem with free space","Validate global git config occasionally ('git config --list --global') so silent breakage surfaces early","Install git and keep it on PATH in build environments"],"tags":["zed","extension","grammar","git","init","filesystem"],"backgroundTag":"git-init-failure","analyzedSha":"f4178619acd0d47ea1f76a2025c42962c6d6638c","analyzedAt":"2026-08-20T19:29:52.058Z","contentChangedAt":"2026-08-20T19:29:52.058Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}