GitoxideLabs/gitoxide · error

Cannot combine --in-place with an explicit output file

Error message

Cannot combine --in-place with an explicit output file

What it means

The `gix config fmt` command formats repository configuration files. It throws this error when `--in-place` (rewrite the source file) is combined with an explicit output file (`--out`), because the two output destinations are mutually exclusive — the operation cannot both write back to the input file and write to a separate path.

Solutions

  1. Remove the `--in-place` flag if you want the formatted output written to the explicit file
  2. Remove the `--out`/output-file argument if you want the source file rewritten in place
  3. Validate arguments before invoking to ensure only one of the two output modes is set

Example fix

// before
let args = ["gix", "config", "fmt", "--in-place", "-o", "formatted.cfg"];
// after
let args = ["gix", "config", "fmt", "--in-place"]; // or drop --in-place and keep -o
Defensive patterns

Strategy: validation

Validate before calling

if args.in_place && args.out_file.is_some() {
    return Err(anyhow!("Cannot combine --in-place with an explicit output file"));
}

Type guard

fn is_valid_output_mode(in_place: bool, out_file: &Option<PathBuf>) -> bool {
    !(in_place && out_file.is_some())
}

Prevention

When it happens

Trigger: Calling the `config fmt` CLI subcommand (function `fmt` in gitoxide-core/src/repository/config.rs) with both `in_place=true` and `out_file=Some(path)`.

Common situations: A developer scripting config reformatting passes `--in-place` from habit plus a leftover `-o out.tmp` argument from an earlier non-in-place invocation; CI scripts merge flags from two sources.

Understand the failure class

Background: "mutually exclusive" flag errors: what "can't supply both nx and xx", "--raw is not compatible with -i" and "cannot be used with" mean, and how to fix them — this error's family across 29 libraries.

Related errors


AI-assisted analysis of GitoxideLabs/gitoxide@e73179060b (2026-09-08). Data as JSON: /api/errors/ad3d5553d6533cf5. Report an issue: GitHub.

Appendix: source

Thrown at gitoxide-core/src/repository/config.rs:96

            .is_some_and(|(next_section, _)| next_section.header().name() != section.header().name())
        {
            writeln!(&mut out)?;
        }
    }
    Ok(())
}

/// Format the git configuration file at `in_file`, or the repository-local configuration if `in_file`
/// is `None`, writing the result back in place, to `out_file`, or to `out` (stdout) respectively.
pub fn fmt(
    repo: Option<gix::Repository>,
    in_file: Option<std::path::PathBuf>,
    out_file: Option<std::path::PathBuf>,
    in_place: bool,
    mut out: impl std::io::Write,
) -> Result<()> {
    if in_place && out_file.is_some() {
        bail!("Cannot combine --in-place with an explicit output file");
    }
    let source = match in_file {
        Some(path) => path,
        None => repo
            .context("Formatting the repository-local configuration requires being in a repository")?
            .common_dir()
            .join("config"),
    };
    let lock = in_place
        .then(|| {
            gix::lock::File::acquire_to_update_resource(&source, gix::lock::acquire::Fail::Immediately, None)
                .with_context(|| format!("Could not lock configuration file at '{}'", source.display()))
        })
        .transpose()?;
    let input = std::fs::read(&source)
        .with_context(|| format!("Could not read configuration file at '{}'", source.display()))?;
    let formatted = gix::config::format::normalize(&input, Default::default())?;
    match (lock, out_file) {

View on GitHub (pinned to e73179060b)