gitbutlerapp/gitbutler · error
Cannot handle changes while in edit mode. Please exit edit…
Error message
Cannot handle changes while in edit mode. Please exit edit mode first.
What it means
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.
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.
Example fix
// before
handle_changes(ctx, assignments, opts)?;
// after
if !matches!(operating_mode(ctx, perm.read_permission())?, OperatingMode::OpenWorkspace) {
anyhow::bail!("exit edit mode before handling changes");
}
handle_changes(ctx, assignments, opts)?; Defensive patterns
Strategy: validation
Validate before calling
let mode = gitbutler_operating_mode::operating_mode(ctx, perm.read_permission())?;
if !matches!(mode, OperatingMode::OpenWorkspace) {
anyhow::bail!("workspace is in edit mode; exit edit mode before handling changes");
} Type guard
fn can_handle_changes(mode: &OperatingMode) -> bool { matches!(mode, OperatingMode::OpenWorkspace) } Try / catch
match on_uncommitted_changes(...) {
Err(e) if e.to_string().contains("edit mode") => {
// prompt user to finish/abort the commit edit, then retry
}
other => other?,
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.
Related errors
- Starting index state can only be fetched while in edit mode
- A 'but' binary already exists at
- --ai cannot be combined with a resolve subcommand. For one…
- An edge with desired order
- Branch ' ' already exists
AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18).
Data as JSON: /api/errors/e35db47ed455b326.
Report an issue: GitHub.
Appendix: source
Thrown at crates/but-action/src/lib.rs:126
snapshot_after,
&response,
)?
};
response.map(|outcome| (id, outcome))
}
/// Prepare repository state for handle-changes.
///
/// This preserves the legacy preconditions from the old context-owning action flow:
/// ensure a default target exists, reject edit mode, and switch back to the workspace
/// branch when the repository is currently outside the workspace. Callers must hold
/// exclusive worktree access and pass its permission through so no nested guard is
/// acquired here.
fn prepare_handle_changes(ctx: &mut Context, perm: &mut RepoExclusive) -> anyhow::Result<()> {
default_target_setting_if_none(ctx)?;
match gitbutler_operating_modes::operating_mode(ctx, perm.read_permission())? {
OperatingMode::OpenWorkspace => Ok(()),
OperatingMode::Edit(_) => Err(anyhow::anyhow!(
"Cannot handle changes while in edit mode. Please exit edit mode first."
)),
OperatingMode::OutsideWorkspace(_) => {
let target_ref: gitbutler_reference::RemoteRefname = ctx
.project_meta()?
.target_ref_or_err()?
.to_string()
.parse()?;
gitbutler_branch_actions::set_base_branch(ctx, &target_ref, perm).map(|_| ())
}
}
}
fn default_target_setting_if_none(ctx: &Context) -> anyhow::Result<()> {
if ctx.project_meta()?.target_ref.is_some() {
return Ok(());
}
// Lets do the equivalent of `git symbolic-ref refs/remotes/origin/HEAD --short` to guess the default target.View on GitHub (pinned to 58e5313667)