gitbutlerapp/gitbutler · error

Invalid conflict stage

Error message

Invalid conflict stage '{}'

What it means

restore_index_conflicts rebuilds conflicted index entries from a snapshot, where each conflict is stored under a path keyed "<stage>/<path>" with stage 1 (Base), 2 (Ours), or 3 (Theirs). If the stage prefix is any other byte string the snapshot data is malformed or from an unknown format, so the function bails instead of writing a wrong index entry.

Solutions

  1. Restore from a different (older/newer) snapshot whose conflict data is well-formed.
  2. Inspect the snapshot tree entry names and fix the stage prefix to 1, 2, or 3 if you control the data.
  3. If the snapshot is corrupted, reconstruct the index manually (git checkout --conflict style) instead of oplog restore.
  4. Report it as a bug if a normal GitButler-produced snapshot triggers this - it indicates a snapshot-format regression.

Example fix

// before (snapshot conflict entry key)
"4/src/lib.rs"
// after
"1/src/lib.rs" // valid stages: 1 (Base), 2 (Ours), 3 (Theirs)
Defensive patterns

Strategy: try-catch

Try / catch

match restore_snapshot(&ctx, id) {
    Err(e) if e.to_string().contains("Invalid conflict stage") => {
        // snapshot data malformed: pick another snapshot or rebuild index manually
    }
    other => other?,
}

Prevention

When it happens

Trigger: Resetting the index to a snapshot tree (via reset_index_to_restore / restore_snapshot) when an entry under additional index-conflict data has a stage prefix other than 1, 2, or 3 - i.e. corrupted or hand-modified snapshot data, or a snapshot written by a different/newer format.

Common situations: Manually edited snapshot trees in refs/gitbutler/...; snapshots from incompatible GitButler versions; corrupted oplog storage; tests crafting snapshot entries with wrong keys.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


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

Appendix: source

Thrown at crates/gitbutler-oplog/src/oplog.rs:501

fn restore_index_conflicts(index: &mut gix::index::State, conflict_tree: gix::Id) -> Result<()> {
    let conflict_tree = conflict_tree.object()?.try_into_tree()?;
    let mut recorder = gix::traverse::tree::Recorder::default();
    conflict_tree.traverse().depthfirst(&mut recorder)?;

    let mut to_remove = BTreeSet::new();
    for record in &recorder.records {
        if record.mode.is_tree() {
            continue;
        }
        let path = &record.filepath;
        let slash = path
            .find_byte(b'/')
            .context("BUG: expecting <stage>/<path>")?;
        let stage = match &path[..slash] {
            b"1" => Stage::Base,
            b"2" => Stage::Ours,
            b"3" => Stage::Theirs,
            stage => bail!("Invalid conflict stage '{}'", stage.as_bstr()),
        };
        let path = path[slash + 1..].as_bstr();

        index.dangerously_push_entry(
            Default::default(),
            record.oid,
            Flags::from_stage(stage),
            record.mode.into(),
            path,
        );
        to_remove.insert(path);
    }
    index.remove_entries(|_idx, path, entry| {
        entry.flags.stage() == Stage::Unconflicted && to_remove.contains(path)
    });
    index.sort_entries();
    Ok(())
}

View on GitHub (pinned to 58e5313667)