{"record":{"id":"e0bae2a0976c001a","repo":"gitbutlerapp/gitbutler","slug":"starting-index-state-can-only-be-fetched-while-in","errorCode":null,"errorMessage":"Starting index state can only be fetched while in edit mode","messagePattern":"Starting index state can only be fetched while in edit mode","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/gitbutler-edit-mode/src/lib.rs","lineNumber":440,"sourceCode":"}\n\n#[derive(Serialize, Debug, Clone)]\n#[cfg_attr(feature = \"export-schema\", derive(schemars::JsonSchema))]\n#[serde(rename_all = \"camelCase\")]\npub struct ConflictEntryPresence {\n    pub ours: bool,\n    pub theirs: bool,\n    pub ancestor: bool,\n}\n#[cfg(feature = \"export-schema\")]\nbut_schemars::register_sdk_type!(ConflictEntryPresence);\n\npub(crate) fn starting_index_state(\n    ctx: &Context,\n    perm: &RepoShared,\n) -> Result<Vec<(TreeChange, Option<ConflictEntryPresence>)>> {\n    let OperatingMode::Edit(metadata) = operating_mode(ctx, perm)? else {\n        bail!(\"Starting index state can only be fetched while in edit mode\")\n    };\n\n    let repo = &*ctx.repo.get()?;\n    let commit = repo.find_commit(metadata.commit_oid)?;\n    let commit_parent_tree = if commit.is_conflicted() {\n        but_core::Commit::try_from(commit.clone())?\n            .tree_id_or_kind(but_core::commit::TreeKind::Base)?\n            .detach()\n    } else {\n        commit\n            .parent_ids()\n            .next()\n            .context(\"edited commit had no parent\")?\n            .object()?\n            .try_into_commit()?\n            .tree_id()?\n            .detach()\n    };","sourceCodeStart":422,"sourceCodeEnd":458,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/gitbutler-edit-mode/src/lib.rs#L422-L458","documentation":"starting_index_state returns the diff between the index and the initial commit captured when edit mode was entered. It only makes sense while the repository is in OperatingMode::Edit; in any other mode there is no edit-session metadata to compare against, so the function bails with this message.","triggerScenarios":"Calling starting_index_state when operating_mode(ctx, perm) returns anything other than OperatingMode::Edit(_), e.g. the workspace is in OpenWorkspace mode, no workspace is active, or edit mode was exited/reset before the call.","commonSituations":"A UI command races with the user leaving edit mode; calling the internal function from another module without first checking in_edit_mode; project freshly opened where edit-mode metadata was never written; oplog/undo restored a snapshot that left a non-edit mode active.","solutions":["Check in_edit_mode(ctx, perm) (or match operating_mode) before calling starting_index_state.","Enter edit mode first via the mode-transition API, then fetch the starting index state.","If a race with mode exit is expected, treat the bail as an empty/no-session result in the caller.","Refresh project/mode state (reload workspace) if you believe edit mode is active but the metadata is missing."],"exampleFix":"// before\nlet state = starting_index_state(&ctx, &perm)?;\n// after\nif !in_edit_mode(&ctx, &perm)? {\n    return Ok(Vec::new()); // not in edit mode: no starting index state\n}\nlet state = starting_index_state(&ctx, &perm)?;","handlingStrategy":"type-guard","validationCode":"let in_edit = matches!(operating_mode(&ctx, &perm)?, OperatingMode::Edit(_));","typeGuard":"fn is_edit_mode(mode: &OperatingMode) -> bool {\n    matches!(mode, OperatingMode::Edit(_))\n}","tryCatchPattern":"match starting_index_state(&ctx, &perm) {\n    Err(e) if e.to_string().contains(\"only be fetched while in edit mode\") => Ok(Vec::new()),\n    other => other,\n}","preventionTips":["Check in_edit_mode before any edit-session-specific API","Centralize mode checks in one helper instead of scattering matches","Handle mode-exit races by treating the bail as an empty result where semantically valid"],"tags":["git","edit-mode","operating-mode","precondition"],"backgroundTag":"invalid-state-transition","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"}