{"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":null,"httpStatus":null,"severity":"warning","filePath":"crates/but-rebase/src/commit.rs","lineNumber":39,"sourceCode":"/// as per `repo` configuration, and write the changes back to `destination`, keeping\n/// user comments and custom formatting.\npub fn save_author_if_unset_in_repo<'a, 'b>(\n    repo: &gix::Repository,\n    destination: Source,\n    name: impl Into<&'a BStr>,\n    email: impl Into<&'b BStr>,\n) -> anyhow::Result<()> {\n    let config = repo.config_snapshot();\n    let name = config\n        .string(gix::config::tree::User::NAME)\n        .is_none()\n        .then_some(name.into());\n    let email = config\n        .string(gix::config::tree::User::EMAIL)\n        .is_none()\n        .then_some(email.into());\n    if name.is_none() && email.is_none() {\n        bail!(\"Refusing to overwrite an existing user.name and user.email\");\n    }\n\n    but_core::git_config::edit_config(Some(repo), destination, |config| {\n        if let Some(name) = name {\n            config.set_raw_value(gix::config::tree::User::NAME, name)?;\n        }\n        if let Some(email) = email {\n            config.set_raw_value(gix::config::tree::User::EMAIL, email)?;\n        }\n        Ok(())\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///","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but-rebase/src/commit.rs#L21-L57","documentation":"This function intentionally sets user.name/user.email in a repo config only when they are missing. If both values already exist, there is nothing to backfill and overwriting user-identity config would be destructive, so it bails. This protects a user's configured identity from being clobbered by automation.","triggerScenarios":"Calling `save_author_if_unset_in_repo` on a repository whose config already has both user.name and user.email set, while passing a destination config for the write.","commonSituations":"Running GitButler setup in an already-configured repo; running the author-backfill twice; shared machines where global git identity was configured before the tool ran.","solutions":["Do nothing — the identity is already configured; skip the call when `git config user.name` and `user.email` both succeed","Remove the pre-call check conflict by only invoking this during first-run/init flows","If you truly intend to overwrite, edit the config explicitly instead of using this guard-railed API"],"exampleFix":"// before: unconditional call\nsave_author_if_unset_in_repo(&repo, &destination, name, email)?;\n// after: check first\nlet has = repo.config_snapshot()?.string(\"user.name\").is_some();\nif !has { save_author_if_unset_in_repo(&repo, &destination, name, email)?; }","handlingStrategy":"try-catch","validationCode":"let configured = repo.config_snapshot()?;\nlet has_name = configured.string(\"user.name\").is_some();\nlet has_email = configured.string(\"user.email\").is_some();\n// only call the backfill when something is missing\nif !(has_name && has_email) { save_author_if_unset_in_repo(...)?; }","typeGuard":"fn identity_fully_configured(repo: &gix::Repository) -> bool {\n    let cfg = repo.config_snapshot();\n    cfg.map(|c| c.string(\"user.name\").is_some() && c.string(\"user.email\").is_some()).unwrap_or(false)\n}","tryCatchPattern":"match save_author_if_unset_in_repo(&repo, dest, name, email) {\n    Ok(()) => {},\n    Err(e) if e.to_string().contains(\"Refusing to overwrite\") => {\n        // identity already set: this is fine, continue\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Call this only during first-run/init flows","Check existing user.name/user.email before invoking","Never use this API to intentionally change identity"],"tags":["git","config","identity"],"backgroundTag":"conflicting-config-options","analyzedSha":"58e5313667b857ef39a730e380af31816a7b1768","analyzedAt":"2026-09-18T06:50:32.052Z","contentChangedAt":"2026-09-18T06:50:32.052Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}