{"record":{"id":"8c2c80563f46a108","repo":"gitbutlerapp/gitbutler","slug":"refusing-to-overwrite-an-existing-user-name-and-us","errorCode":null,"errorMessage":"Refusing to overwrite an existing user.name and user.email","messagePattern":"Refusing to overwrite an existing user\\.name and user\\.email","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"warning","filePath":"crates/but-rebase/src/commit.rs","lineNumber":69,"sourceCode":"\n    if !config_path.exists() {\n        std::fs::create_dir_all(config_path.parent().context(\"Git user config is never /\")?)?;\n        std::fs::File::create(&config_path)?;\n    }\n\n    let mut config = gix::config::File::from_path_no_includes(config_path.clone(), destination)?;\n    let mut something_was_set = false;\n    if let Some(name) = name {\n        config.set_raw_value(gix::config::tree::User::NAME, name)?;\n        something_was_set = true;\n    }\n    if let Some(email) = email {\n        config.set_raw_value(gix::config::tree::User::EMAIL, email)?;\n        something_was_set = true;\n    }\n\n    if !something_was_set {\n        bail!(\"Refusing to overwrite an existing user.name and user.email\");\n    }\n\n    config.write_to(\n        &mut std::fs::OpenOptions::new()\n            .write(true)\n            .create(false)\n            .truncate(true)\n            .open(config_path)?,\n    )?;\n\n    Ok(())\n}\n\n/// Use the given `commit` and possibly sign it, replacing a possibly existing signature,\n/// or removing the signature if GitButler is not configured to keep it.\n///\n/// Signatures will be removed automatically if signing is disabled to prevent an amended commit\n/// to use the old signature.","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/caf1f223d3cfb94488c9198ad34487c6006c648f/crates/but-rebase/src/commit.rs#L51-L87","documentation":"`save_author_if_unset_in_repo` writes user.name/user.email into a destination config file only for values unset in the repository. When the repo already defines both, nothing would be set, and the function bails instead of rewriting (truncating) the destination file as a no-op — the message means 'both values already exist, nothing to copy'.","triggerScenarios":"Calling `save_author_if_unset_in_repo` when both `user.name` and `user.email` are already configured for the repository (global or local), which is the common case in worktree-creation flows that copy identity.","commonSituations":"Developer workstations with a global git identity already set; provisioning scripts that assume an unconfigured repo; CI images that bake in an identity.","solutions":["Treat this bail as 'identity already present': check the repo config first and skip the call when both values exist","If the intent is to force-copy identity, use a write path that overwrites unconditionally","Unset one of the values if this helper genuinely needs to write something"],"exampleFix":"// before\nbut_rebase::commit::save_author_if_unset_in_repo(&repo, Source::Local, name, email)?; // bails when both set\n\n// after: treat 'already configured' as success\nlet cfg = repo.config_snapshot();\nlet both_set = cfg.string(gix::config::tree::User::NAME).is_some()\n    && cfg.string(gix::config::tree::User::EMAIL).is_some();\nif !both_set {\n    but_rebase::commit::save_author_if_unset_in_repo(&repo, Source::Local, name, email)?;\n}","handlingStrategy":"validation","validationCode":"// Rust: skip the copy when identity is already fully configured\nlet cfg = repo.config_snapshot();\nlet both_set = cfg.string(gix::config::tree::User::NAME).is_some()\n    && cfg.string(gix::config::tree::User::EMAIL).is_some();\nif !both_set {\n    but_rebase::commit::save_author_if_unset_in_repo(&repo, Source::Local, name, email)?;\n}","typeGuard":null,"tryCatchPattern":"Catch the 'Refusing to overwrite' bail and treat it as success when the intent was 'ensure an identity exists' — the repo already has user.name and user.email.","preventionTips":["Check the repo config for both values before calling identity-copy helpers","Use an explicit overwrite path when forcing identity, instead of the if-unset helper"],"tags":["git-config","user-identity","worktree","gitbutler"],"backgroundTag":"git-user-config-already-set","analyzedSha":"caf1f223d3cfb94488c9198ad34487c6006c648f","analyzedAt":"2026-08-20T07:55:40.983Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}