{"record":{"id":"e35db47ed455b326","repo":"gitbutlerapp/gitbutler","slug":"cannot-handle-changes-while-in-edit-mode-please-e","errorCode":null,"errorMessage":"Cannot handle changes while in edit mode. Please exit edit mode first.","messagePattern":"Cannot handle changes while in edit mode\\. Please exit edit mode first\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but-action/src/lib.rs","lineNumber":126,"sourceCode":"            snapshot_after,\n            &response,\n        )?\n    };\n    response.map(|outcome| (id, outcome))\n}\n\n/// Prepare repository state for handle-changes.\n///\n/// This preserves the legacy preconditions from the old context-owning action flow:\n/// ensure a default target exists, reject edit mode, and switch back to the workspace\n/// branch when the repository is currently outside the workspace. Callers must hold\n/// exclusive worktree access and pass its permission through so no nested guard is\n/// acquired here.\nfn prepare_handle_changes(ctx: &mut Context, perm: &mut RepoExclusive) -> anyhow::Result<()> {\n    default_target_setting_if_none(ctx)?;\n    match gitbutler_operating_modes::operating_mode(ctx, perm.read_permission())? {\n        OperatingMode::OpenWorkspace => Ok(()),\n        OperatingMode::Edit(_) => Err(anyhow::anyhow!(\n            \"Cannot handle changes while in edit mode. Please exit edit mode first.\"\n        )),\n        OperatingMode::OutsideWorkspace(_) => {\n            let target_ref: gitbutler_reference::RemoteRefname = ctx\n                .project_meta()?\n                .target_ref_or_err()?\n                .to_string()\n                .parse()?;\n            gitbutler_branch_actions::set_base_branch(ctx, &target_ref, perm).map(|_| ())\n        }\n    }\n}\n\nfn default_target_setting_if_none(ctx: &Context) -> anyhow::Result<()> {\n    if ctx.project_meta()?.target_ref.is_some() {\n        return Ok(());\n    }\n    // Lets do the equivalent of `git symbolic-ref refs/remotes/origin/HEAD --short` to guess the default target.","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but-action/src/lib.rs#L108-L144","documentation":"prepare_handle_changes checks the repository's operating mode before applying file-assignment changes; it only allows the OpenWorkspace mode. If the workspace is currently in Edit mode (a commit is being edited), handling changes is refused because exclusive worktree access is held by the edit session and mutations would conflict with it. The user must exit edit mode first.","triggerScenarios":"Calling on_uncommitted_changes (via prepare_handle_changes) while gitbutler_operating_mode reports OperatingMode::Edit — i.e. a stack/commit edit session is active in the workspace.","commonSituations":"An edit-mode session was left open from a previous operation or crashed without cleanup; a script/automation drives `but` change-handling while the UI has an edit in progress; a developer started amending/rewording a commit and then programmatically tried to assign files.","solutions":["Exit edit mode first (finish or abort the commit edit in the UI/CLI), then retry the operation.","Check the current mode programmatically via gitbutler_operating_mode before calling, and only proceed on OperatingMode::OpenWorkspace.","If edit mode is stale (no edit actually in progress), reset the workspace state so the mode returns to OpenWorkspace, then retry."],"exampleFix":"// before\nhandle_changes(ctx, assignments, opts)?;\n\n// after\nif !matches!(operating_mode(ctx, perm.read_permission())?, OperatingMode::OpenWorkspace) {\n    anyhow::bail!(\"exit edit mode before handling changes\");\n}\nhandle_changes(ctx, assignments, opts)?;","handlingStrategy":"validation","validationCode":"let mode = gitbutler_operating_mode::operating_mode(ctx, perm.read_permission())?;\nif !matches!(mode, OperatingMode::OpenWorkspace) {\n    anyhow::bail!(\"workspace is in edit mode; exit edit mode before handling changes\");\n}","typeGuard":"fn can_handle_changes(mode: &OperatingMode) -> bool { matches!(mode, OperatingMode::OpenWorkspace) }","tryCatchPattern":"match on_uncommitted_changes(...) {\n    Err(e) if e.to_string().contains(\"edit mode\") => {\n        // prompt user to finish/abort the commit edit, then retry\n    }\n    other => other?,\n}","preventionTips":["Always finish or abort an active commit edit before running change-handling operations.","Check operating mode at the start of automation scripts that touch the workspace.","Clean up stale edit-mode state after a crashed session."],"tags":["edit-mode","operating-mode","workspace-state","conflict"],"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"}