nikivdev/code · error
git config --global {} failed
Error message
git config --global {} failed What it means
`git_config_global_set` runs `git config --global <key> <value>` and checks the exit status; when git exits non-zero it bails with this message. The `with_context` above catches spawn failures, so this error specifically means git ran but the config write was rejected.
Source
Thrown at src/push_hook.rs:194
.context("failed to read global core.hooksPath")?;
if !output.status.success() {
return Ok(None);
}
let value = String::from_utf8_lossy(&output.stdout).trim().to_string();
if value.is_empty() {
return Ok(None);
}
Ok(Some(config::expand_path(&value)))
}
fn git_config_global_set(key: &str, value: &Path) -> Result<()> {
let status = Command::new("git")
.args(["config", "--global", key, &value.to_string_lossy()])
.status()
.with_context(|| format!("failed to set git config {key}"))?;
if !status.success() {
bail!("git config --global {} failed", key);
}
Ok(())
}
fn git_config_global_unset(key: &str) -> Result<()> {
let status = Command::new("git")
.args(["config", "--global", "--unset", key])
.status()
.with_context(|| format!("failed to unset git config {key}"))?;
if !status.success() {
bail!("git config --global --unset {} failed", key);
}
Ok(())
}
fn resolve_repo_root() -> Result<PathBuf> {
let output = Command::new("git")
.args(["rev-parse", "--show-toplevel"])View on GitHub (pinned to a747e741ae)
Solutions
- Verify `git config --global core.hooksPath /tmp/x` works manually to see git's real error
- Ensure $HOME is set and writable (`echo $HOME`, `touch ~/.gitconfig`)
- Fix or remove a corrupt/unreadable global config file (~/.gitconfig or ~/.config/git/config)
- Check permissions: `ls -l ~/.gitconfig`; chown/chmod if it is root-owned
- If HOME is unset (CI/systemd), set HOME or use `git config --file` explicitly
Example fix
// before: CI step with no HOME cargo run -- push hooks install # git config --global core.hooksPath failed // after env: HOME: /home/ci cargo run -- push hooks install
Defensive patterns
Strategy: try-catch
Validate before calling
// preflight: ensure global git config is writable
let home = std::env::var("HOME").map(std::path::PathBuf::from)?;
let cfg = home.join(".gitconfig");
if let Some(dir) = cfg.parent() {
assert!(dir.exists(), "HOME dir missing: {}", dir.display());
}
let probe = std::process::Command::new("git")
.args(["config", "--global", "--list"])
.status()?;
assert!(probe.success(), "git global config unreadable/broken"); Try / catch
match install_hooks() {
Ok(()) => {},
Err(e) if e.to_string().contains("git config --global") => {
eprintln!("fix global git config (HOME writable, no corrupt [include]) and retry: {e}");
}
Err(e) => return Err(e),
} Prevention
- Ensure $HOME is set and writable before running in CI/containers
- Keep ~/.gitconfig free of broken [include] paths
- Run `git config --global --list` as a smoke test in setup scripts
- Avoid running installs as root with a read-only home
When it happens
Trigger: Calling `install_hooks` (via `git_config_global_set("core.hooksPath", ...)`) when the global git config is unwritable or git rejects the operation: no HOME set, $HOME/.gitconfig or ~/.config/git/config unreadable/corrupt, permission denied on the config file, or invalid config include paths.
Common situations: CI containers running as a different user with no writable $HOME; read-only home directories; a locked or root-owned .gitconfig; malformed [include] directives in the global config causing git to fail.
Related errors
- git config --global --unset {} failed
- Lin.app is not running
- resolver {} failed for {}: {}
- failed to stash working tree: {}
- git status failed with {}
AI-assisted analysis of nikivdev/code@a747e741ae (2026-09-01).
Data as JSON: /api/errors/35c2bb55a0769f6e.
Report an issue: GitHub.