{"record":{"id":"4418748002c03310","repo":"nikivdev/code","slug":"git-config-global-unset-all-failed","errorCode":null,"errorMessage":"git config --global --unset-all {} failed","messagePattern":"git config --global --unset-all (.+?) failed","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/ssh.rs","lineNumber":485,"sourceCode":"        .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\nfn add_url_rewrite(key: &str, desired: &[&str]) -> Result<bool> {\n    let existing = git_config_get_all(key)?;\n    let mut changed = false;\n\n    for value in desired {\n        if existing.iter().any(|val| val == value) {\n            continue;\n        }\n        git_config_add(key, value)?;\n        changed = true;\n    }\n\n    Ok(changed)","sourceCodeStart":467,"sourceCodeEnd":503,"githubUrl":"https://github.com/nikivdev/code/blob/a747e741ae92c09071d0ae946ab48488adcff1ce/src/ssh.rs#L467-L503","documentation":"git_config_unset_all runs `git config --global --unset-all <key> <value>` (used by remove_url_rewrite to delete matching multi-valued entries) and bails if git exits nonzero. Note git also exits nonzero when the key/value is simply not present, so a no-op cleanup can surface as this error.","triggerScenarios":"remove_url_rewrite calls git_config_unset_all when the global config is unwritable/corrupt, HOME is misconfigured, a config.lock exists — or when no matching entry exists so git returns exit code 5 (nothing to unset).","commonSituations":"Trying to remove a rewrite that was never added (idempotent cleanup treated as failure); CI environments with read-only HOME; leftover config.lock; malformed gitconfig preventing parsing.","solutions":["Treat git's 'nothing to unset' exit code (5) as success so cleanup is idempotent","Check whether the key/value actually exists with `git config --global --get-all <key>`","Remove stale ~/.gitconfig.lock and verify the config parses","Ensure HOME is writable in the execution environment"],"exampleFix":"// before: any nonzero exit is an error\nif !status.success() {\n    anyhow::bail!(\"git config --global --unset-all {} failed\", key);\n}\n// after: tolerate 'nothing to unset'\nif !status.success() && status.code() != Some(5) {\n    anyhow::bail!(\"git config --global --unset-all {} failed\", key);\n}","handlingStrategy":"validation","validationCode":"fn rewrite_exists(key: &str, value: &str) -> bool {\n    std::process::Command::new(\"git\")\n        .args([\"config\", \"--global\", \"--get-all\", key, value])\n        .output()\n        .map(|o| o.status.success()).unwrap_or(false)\n}\n// only attempt unset when the entry actually exists\nif rewrite_exists(key, value) { remove_url_rewrite(key)?; }","typeGuard":null,"tryCatchPattern":"match remove_url_rewrite(key) {\n    Ok(_) => println!(\"rewrite removed (or already absent)\"),\n    Err(e) if e.to_string().contains(\"--unset-all\") => {\n        // git exits 5 when there is nothing to unset — treat as idempotent success\n        eprintln!(\"unset failed: {e:#}; entry may not exist\");\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Check entry existence with `git config --global --get-all` before unsetting","Treat git's exit code 5 (nothing to unset) as success for idempotent cleanup","Keep HOME writable and free of stale config.lock files","Don't call remove for rewrites that were never added"],"tags":["git","config","idempotency","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"}