gitbutlerapp/gitbutler · error

editing config through a repository is not supported

Error message

editing {source:?} config through a repository is not supported

What it means

edit_repo_config() edits a git config file through a repository handle, but system-level and installation-level config sources have no repository scope. Attempting to route edits to those sources through a repo is rejected up front with this error.

Solutions

  1. Target Source::Local (repository) config for repo-scoped edits
  2. Edit system/installation config directly with gix::config::File::from_paths and write it back outside the repo API
  3. Log/inspect which source the value currently comes from before editing
  4. Guard calls so only repo-scoped sources reach this API

Example fix

// before
edit_repo_config(&repo, gix::config::Source::System, |f| { f.set_raw_value("user.name", "x") })?;
// after
let source = gix::config::Source::Local;
edit_repo_config(&repo, source, |f| { f.set_raw_value("user.name", "x") })?;
Defensive patterns

Strategy: validation

Validate before calling

fn repo_scoped(source: gix::config::Source) -> bool {
    !matches!(source, gix::config::Source::System | gix::config::Source::GitInstallation)
}

Try / catch

match edit_repo_config(&repo, source, edit) {
    Err(e) if e.to_string().contains("not supported") => edit_global_config_file_directly(),
    other => other?,
}

Prevention

When it happens

Trigger: Calling any of the wrappers (add_remote_to_config, persist_to_local_config, set_target_ref_and_init_project, edit_git_config, setup_local_remote, set_exclude_decoration) with source = Source::System or Source::GitInstallation, typically because the config lookup resolved to a global/system file.

Common situations: A setting being modified actually lives in /etc/gitconfig or the installation prefix config; misconfigured source detection passing the wrong enum variant; tests that point config sources at system scope.

Related errors


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

Appendix: source

Thrown at crates/but-core/src/git_config.rs:76

        config
            .commit()
            .with_context(|| format!("failed to commit git config at {}", path.display()))?;
    }
    Ok(changed)
}

/// Edit the Git config for `source` using `repo`, resolving its path as described in [`edit_config()`].
/// Write it back if the edited configuration differs from its original state.
pub fn edit_repo_config(
    repo: &gix::Repository,
    source: gix::config::Source,
    edit: impl FnOnce(&mut gix::config::File) -> Result<()>,
) -> Result<bool> {
    if matches!(
        source,
        gix::config::Source::System | gix::config::Source::GitInstallation
    ) {
        bail!("editing {source:?} config through a repository is not supported");
    }
    edit_config(Some(repo), source, edit)
}

/// Set the entry in `config` identified by the dotted `key` (like `section.value` or `section.subsection.value`) to `value`.
/// This will create sections as needed, and remove all previous values under the same section with the same name.
pub fn set_config_value(config: &mut gix::config::File, key: &str, value: &str) -> Result<()> {
    remove_config_value(config, key)?;
    let key = key
        .try_as_key()
        .with_context(|| format!("invalid git config key: {key}"))?;
    config
        .section_mut_or_create_new(key.section_name, key.subsection_name)?
        .set(key.value_name, value)?;
    Ok(())
}

/// Ensure `value` is present in `config` for the multi-valued Git entry identified by `key`.

View on GitHub (pinned to 58e5313667)