{"record":{"id":"1baa7b94b3b63424","repo":"nikivdev/code","slug":"git-config-global-add-failed","errorCode":null,"errorMessage":"git config --global --add {} failed","messagePattern":"git config --global --add (.+?) failed","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/ssh.rs","lineNumber":472,"sourceCode":"        .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\nfn git_config_unset_all(key: &str, value: &str) -> Result<()> {\n    let status = Command::new(\"git\")\n        .args([\"config\", \"--global\", \"--unset-all\", key, value])\n        .status()\n        .context(\"failed to run git config\")?;\n\n    if !status.success() {\n        anyhow::bail!(\"git config --global --unset-all {} failed\", key);\n    }\n\n    Ok(())\n}\n","sourceCodeStart":454,"sourceCodeEnd":490,"githubUrl":"https://github.com/nikivdev/code/blob/a747e741ae92c09071d0ae946ab48488adcff1ce/src/ssh.rs#L454-L490","documentation":"git_config_add runs `git config --global --add <key> <value>` (used by add_url_rewrite to append e.g. insteadOf/url rewrite entries without replacing existing values) and bails if git exits nonzero. The multi-valued config entry was not appended.","triggerScenarios":"add_url_rewrite calls git_config_add while the global config is unwritable, corrupt, HOME is unset/misconfigured, or a config.lock is present — git exits nonzero and the add is lost.","commonSituations":"CI container without writable HOME; ~/.gitconfig.lock left by a crashed git; malformed include directives breaking config parsing; read-only filesystem.","solutions":["Run the exact `git config --global --add <key> <value>` manually to see git's stderr","Remove stale ~/.gitconfig.lock and ensure ~/.gitconfig parses (`git config --global --list`)","Confirm HOME is set and writable in the execution environment","Apply the rewrite entry manually in ~/.gitconfig if automation keeps failing"],"exampleFix":"// before\nanyhow::bail!(\"git config --global --add {} failed\", key);\n// after: surface git diagnostics\nanyhow::bail!(\"git config --global --add {} failed: {}\", key, String::from_utf8_lossy(&output.stderr));","handlingStrategy":"try-catch","validationCode":"// verify global config is writable and not locked before --add\nlet home = std::env::var_os(\"HOME\").map(std::path::PathBuf::from);\nif home.map(|h| h.join(\".gitconfig.lock\").exists()).unwrap_or(false) {\n    eprintln!(\"stale ~/.gitconfig.lock present; git config --add will fail\");\n}","typeGuard":null,"tryCatchPattern":"match add_url_rewrite(key, desired) {\n    Ok(changed) => { if changed { println!(\"rewrite added\"); } }\n    Err(e) if e.to_string().contains(\"git config --global --add\") => {\n        eprintln!(\"failed to append rewrite: {e:#}; add it manually to ~/.gitconfig\");\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Check HOME writability in provisioning scripts before running flows that write git config","Remove stale config.lock files from crashed git operations","Run `git config --global --list` after hand-editing .gitconfig to catch parse errors","Append rewrite rules manually to ~/.gitconfig if automation is blocked"],"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"}