{"record":{"id":"ad3d5553d6533cf5","repo":"GitoxideLabs/gitoxide","slug":"cannot-combine-in-place-with-an-explicit-output","errorCode":null,"errorMessage":"Cannot combine --in-place with an explicit output file","messagePattern":"Cannot combine --in-place with an explicit output file","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"gitoxide-core/src/repository/config.rs","lineNumber":96,"sourceCode":"            .is_some_and(|(next_section, _)| next_section.header().name() != section.header().name())\n        {\n            writeln!(&mut out)?;\n        }\n    }\n    Ok(())\n}\n\n/// Format the git configuration file at `in_file`, or the repository-local configuration if `in_file`\n/// is `None`, writing the result back in place, to `out_file`, or to `out` (stdout) respectively.\npub fn fmt(\n    repo: Option<gix::Repository>,\n    in_file: Option<std::path::PathBuf>,\n    out_file: Option<std::path::PathBuf>,\n    in_place: bool,\n    mut out: impl std::io::Write,\n) -> Result<()> {\n    if in_place && out_file.is_some() {\n        bail!(\"Cannot combine --in-place with an explicit output file\");\n    }\n    let source = match in_file {\n        Some(path) => path,\n        None => repo\n            .context(\"Formatting the repository-local configuration requires being in a repository\")?\n            .common_dir()\n            .join(\"config\"),\n    };\n    let lock = in_place\n        .then(|| {\n            gix::lock::File::acquire_to_update_resource(&source, gix::lock::acquire::Fail::Immediately, None)\n                .with_context(|| format!(\"Could not lock configuration file at '{}'\", source.display()))\n        })\n        .transpose()?;\n    let input = std::fs::read(&source)\n        .with_context(|| format!(\"Could not read configuration file at '{}'\", source.display()))?;\n    let formatted = gix::config::format::normalize(&input, Default::default())?;\n    match (lock, out_file) {","sourceCodeStart":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/GitoxideLabs/gitoxide/blob/e73179060badf27222d790981fac3f84c1830a7e/gitoxide-core/src/repository/config.rs#L78-L114","documentation":"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.","triggerScenarios":"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)`.","commonSituations":"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.","solutions":["Remove the `--in-place` flag if you want the formatted output written to the explicit file","Remove the `--out`/output-file argument if you want the source file rewritten in place","Validate arguments before invoking to ensure only one of the two output modes is set"],"exampleFix":"// before\nlet args = [\"gix\", \"config\", \"fmt\", \"--in-place\", \"-o\", \"formatted.cfg\"];\n// after\nlet args = [\"gix\", \"config\", \"fmt\", \"--in-place\"]; // or drop --in-place and keep -o","handlingStrategy":"validation","validationCode":"if args.in_place && args.out_file.is_some() {\n    return Err(anyhow!(\"Cannot combine --in-place with an explicit output file\"));\n}","typeGuard":"fn is_valid_output_mode(in_place: bool, out_file: &Option<PathBuf>) -> bool {\n    !(in_place && out_file.is_some())\n}","tryCatchPattern":null,"preventionTips":["Use CLI argument groups (clap ArgGroup, mutually exclusive) so the parser rejects the combination upfront","Only pass one of --in-place or -o when scripting","Review flag assembly when merging options from multiple sources"],"tags":["cli","config","argument-validation"],"backgroundTag":"mutually-exclusive-flags","analyzedSha":"e73179060badf27222d790981fac3f84c1830a7e","analyzedAt":"2026-09-08T11:26:50.865Z","contentChangedAt":"2026-09-08T11:26:50.865Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}