{"record":{"id":"1486feb5d99b1b66","repo":"nikivdev/code","slug":"git-config-global-failed-1486fe","errorCode":null,"errorMessage":"git config --global {} failed","messagePattern":"git config --global (.+?) failed","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/ssh.rs","lineNumber":459,"sourceCode":"        return Ok(Vec::new());\n    }\n\n    let stdout = String::from_utf8_lossy(&output.stdout);\n    Ok(stdout\n        .lines()\n        .map(|line| line.trim().to_string())\n        .filter(|line| !line.is_empty())\n        .collect())\n}\n\nfn git_config_set(key: &str, value: &str) -> Result<()> {\n    let status = Command::new(\"git\")\n        .args([\"config\", \"--global\", key, value])\n        .status()\n        .context(\"failed to run git config\")?;\n\n    if !status.success() {\n        anyhow::bail!(\"git config --global {} failed\", key);\n    }\n\n    Ok(())\n}\n\nfn git_config_add(key: &str, value: &str) -> Result<()> {\n    let status = Command::new(\"git\")\n        .args([\"config\", \"--global\", \"--add\", key, value])\n        .status()\n        .context(\"failed to run git config\")?;\n\n    if !status.success() {\n        anyhow::bail!(\"git config --global --add {} failed\", key);\n    }\n\n    Ok(())\n}\n","sourceCodeStart":441,"sourceCodeEnd":477,"githubUrl":"https://github.com/nikivdev/code/blob/a747e741ae92c09071d0ae946ab48488adcff1ce/src/ssh.rs#L441-L477","documentation":"git_config_set runs `git config --global <key> <value>` and bails with this message if git exits nonzero. It means a global git configuration write failed — the key/value never landed in ~/.gitconfig, so dependent behavior (e.g. GIT_SSH_COMMAND setup) will not take effect.","triggerScenarios":"ensure_git_ssh_command / ensure_git_ssh_command_for_sock / ensure_git_ssh_command_wrapper call git_config_set while git cannot write the global config: unwritable or corrupt ~/.gitconfig, HOME unset or pointing somewhere unwritable, include.path loops, or a broken git installation.","commonSituations":"HOME not set in CI containers so git can't resolve the global config path; ~/.gitconfig owned by root or locked by a concurrent git process; malformed config file causing git to abort on any config write; read-only home directory.","solutions":["Run `git config --global <key> <value>` by hand to see git's real stderr","Verify HOME is set and writable (echo $HOME; touch ~/.gitconfig)","Fix or remove a corrupt ~/.gitconfig (git config --global --list to test parsing)","Check for a concurrent git process holding a config.lock and remove stale ~/.gitconfig.lock"],"exampleFix":"// before: key only, no git stderr\nanyhow::bail!(\"git config --global {} failed\", key);\n// after: capture git's diagnostic output\nanyhow::bail!(\"git config --global {} failed: {}\", key, String::from_utf8_lossy(&output.stderr));","handlingStrategy":"try-catch","validationCode":"fn can_write_global_gitconfig() -> bool {\n    std::env::var_os(\"HOME\").map(|h| {\n        let p = std::path::PathBuf::from(h).join(\".gitconfig\");\n        match p.exists() {\n            true => std::fs::OpenOptions::new().append(true).open(&p).is_ok(),\n            false => std::fs::OpenOptions::new().write(true).create_new(true).open(&p).is_ok(),\n        }\n    }).unwrap_or(false)\n}\nif !can_write_global_gitconfig() { eprintln!(\"global git config not writable; fix HOME/permissions first\"); }","typeGuard":null,"tryCatchPattern":"match ensure_git_ssh_command() {\n    Ok(()) => proceed(),\n    Err(e) if e.to_string().contains(\"git config --global\") => {\n        eprintln!(\"could not write global git config: {e:#}; set GIT_SSH_COMMAND env var manually instead\");\n        std::env::set_var(\"GIT_SSH_COMMAND\", ssh_command);\n        proceed();\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Ensure HOME is set and writable, especially in CI containers","Check for and remove stale ~/.gitconfig.lock before writes","Validate ~/.gitconfig parses with `git config --global --list` after manual edits","Prefer capturing git's stderr in the error for faster diagnosis"],"tags":["git","config","environment","process"],"backgroundTag":"git-config-write-failed","analyzedSha":"a747e741ae92c09071d0ae946ab48488adcff1ce","analyzedAt":"2026-09-01T22:43:55.719Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}