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
- Restore from a different (older/newer) snapshot whose conflict data is well-formed.
- Inspect the snapshot tree entry names and fix the stage prefix to 1, 2, or 3 if you control the data.
- If the snapshot is corrupted, reconstruct the index manually (git checkout --conflict style) instead of oplog restore.
- 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
- Only restore snapshots produced by the same GitButler version family
- Never manually edit oplog snapshot trees
- Validate snapshot conflict-entry keys (1|2|3/<path>) when creating snapshots
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
- snapshot additional ref is not a local branch
- targetCommitId in project_meta.toml is null
- targetRef in project_meta.toml is not a remote-tracking…
- Aborting due to empty branch name
- Branch name ' ' collides with existing branch
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)