{"record":{"id":"f17a8a4b2e79b7cf","repo":"gitbutlerapp/gitbutler","slug":"invalid-conflict-stage","errorCode":null,"errorMessage":"Invalid conflict stage '{}'","messagePattern":"Invalid conflict stage '(.+?)'","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/gitbutler-oplog/src/oplog.rs","lineNumber":501,"sourceCode":"fn restore_index_conflicts(index: &mut gix::index::State, conflict_tree: gix::Id) -> Result<()> {\n    let conflict_tree = conflict_tree.object()?.try_into_tree()?;\n    let mut recorder = gix::traverse::tree::Recorder::default();\n    conflict_tree.traverse().depthfirst(&mut recorder)?;\n\n    let mut to_remove = BTreeSet::new();\n    for record in &recorder.records {\n        if record.mode.is_tree() {\n            continue;\n        }\n        let path = &record.filepath;\n        let slash = path\n            .find_byte(b'/')\n            .context(\"BUG: expecting <stage>/<path>\")?;\n        let stage = match &path[..slash] {\n            b\"1\" => Stage::Base,\n            b\"2\" => Stage::Ours,\n            b\"3\" => Stage::Theirs,\n            stage => bail!(\"Invalid conflict stage '{}'\", stage.as_bstr()),\n        };\n        let path = path[slash + 1..].as_bstr();\n\n        index.dangerously_push_entry(\n            Default::default(),\n            record.oid,\n            Flags::from_stage(stage),\n            record.mode.into(),\n            path,\n        );\n        to_remove.insert(path);\n    }\n    index.remove_entries(|_idx, path, entry| {\n        entry.flags.stage() == Stage::Unconflicted && to_remove.contains(path)\n    });\n    index.sort_entries();\n    Ok(())\n}","sourceCodeStart":483,"sourceCodeEnd":519,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/gitbutler-oplog/src/oplog.rs#L483-L519","documentation":"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.","triggerScenarios":"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.","commonSituations":"Manually edited snapshot trees in refs/gitbutler/...; snapshots from incompatible GitButler versions; corrupted oplog storage; tests crafting snapshot entries with wrong keys.","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."],"exampleFix":"// before (snapshot conflict entry key)\n\"4/src/lib.rs\"\n// after\n\"1/src/lib.rs\" // valid stages: 1 (Base), 2 (Ours), 3 (Theirs)","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match restore_snapshot(&ctx, id) {\n    Err(e) if e.to_string().contains(\"Invalid conflict stage\") => {\n        // snapshot data malformed: pick another snapshot or rebuild index manually\n    }\n    other => other?,\n}","preventionTips":["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"],"tags":["git","oplog","snapshot-restore","index-conflicts","validation"],"backgroundTag":"invalid-enum-value","analyzedSha":"58e5313667b857ef39a730e380af31816a7b1768","analyzedAt":"2026-09-18T06:50:32.052Z","contentChangedAt":"2026-09-18T06:50:32.052Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}