gitbutlerapp/gitbutler · warning

Refusing to overwrite an existing user.name and user.email

Error message

Refusing to overwrite an existing user.name and user.email

What it means

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.

Solutions

  1. Do nothing — the identity is already configured; skip the call when `git config user.name` and `user.email` both succeed
  2. Remove the pre-call check conflict by only invoking this during first-run/init flows
  3. If you truly intend to overwrite, edit the config explicitly instead of using this guard-railed API

Example fix

// before: unconditional call
save_author_if_unset_in_repo(&repo, &destination, name, email)?;
// after: check first
let has = repo.config_snapshot()?.string("user.name").is_some();
if !has { save_author_if_unset_in_repo(&repo, &destination, name, email)?; }
Defensive patterns

Strategy: try-catch

Validate before calling

let configured = repo.config_snapshot()?;
let has_name = configured.string("user.name").is_some();
let has_email = configured.string("user.email").is_some();
// only call the backfill when something is missing
if !(has_name && has_email) { save_author_if_unset_in_repo(...)?; }

Type guard

fn identity_fully_configured(repo: &gix::Repository) -> bool {
    let cfg = repo.config_snapshot();
    cfg.map(|c| c.string("user.name").is_some() && c.string("user.email").is_some()).unwrap_or(false)
}

Try / catch

match save_author_if_unset_in_repo(&repo, dest, name, email) {
    Ok(()) => {},
    Err(e) if e.to_string().contains("Refusing to overwrite") => {
        // identity already set: this is fine, continue
    }
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: Conflicting config options: "cannot be used together" — configuration validation errors across open-source libraries — this error's family across 162 libraries.

Related errors


AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18). Data as JSON: /api/errors/8c2c80563f46a108. Report an issue: GitHub.

Appendix: source

Thrown at crates/but-rebase/src/commit.rs:39

/// as per `repo` configuration, and write the changes back to `destination`, keeping
/// user comments and custom formatting.
pub fn save_author_if_unset_in_repo<'a, 'b>(
    repo: &gix::Repository,
    destination: Source,
    name: impl Into<&'a BStr>,
    email: impl Into<&'b BStr>,
) -> anyhow::Result<()> {
    let config = repo.config_snapshot();
    let name = config
        .string(gix::config::tree::User::NAME)
        .is_none()
        .then_some(name.into());
    let email = config
        .string(gix::config::tree::User::EMAIL)
        .is_none()
        .then_some(email.into());
    if name.is_none() && email.is_none() {
        bail!("Refusing to overwrite an existing user.name and user.email");
    }

    but_core::git_config::edit_config(Some(repo), destination, |config| {
        if let Some(name) = name {
            config.set_raw_value(gix::config::tree::User::NAME, name)?;
        }
        if let Some(email) = email {
            config.set_raw_value(gix::config::tree::User::EMAIL, email)?;
        }
        Ok(())
    })?;

    Ok(())
}

/// Use the given `commit` and possibly sign it, replacing a possibly existing signature,
/// or removing the signature if GitButler is not configured to keep it.
///

View on GitHub (pinned to 58e5313667)