gitbutlerapp/gitbutler · error

No stacks found in the workspace

Error message

No stacks found in the workspace

What it means

handle_changes buckets incoming file assignments by stack ID and needs a default stack (the first stack in the workspace) for assignments that do not name one. If the workspace contains no stacks at all, there is nothing to assign files to and no default to fall back on, so this error is thrown.

Solutions

  1. Create a stack/branch in the workspace first (e.g. `but branch create` or via the UI), then retry handling changes.
  2. Verify the workspace actually has stacks (`but` workspace/status output) before submitting assignments.
  3. If stacks should exist but do not, refresh/reload workspace state to fix a potential desync.

Example fix

// before
handle_changes(ctx, assignments, opts)?; // Err: No stacks found in the workspace

// after
let stacks = but_workspace::stacks(ctx)?;
if stacks.is_empty() {
    create_stack(ctx, "my-branch")?;
}
handle_changes(ctx, assignments, opts)?;
Defensive patterns

Strategy: validation

Validate before calling

let stacks = but_workspace::stacks(ctx)?;
if stacks.is_empty() {
    anyhow::bail!("create a stack before assigning changes");
}

Try / catch

match handle_changes(ctx, assignments, opts) {
    Err(e) if e.to_string().contains("No stacks found in the workspace") => {
        // create a branch/stack first, then retry
    }
    other => other?,
}

Prevention

When it happens

Trigger: Calling handle_changes when the computed workspace stack list is empty — the workspace has no applied branches/stacks (everything merged/cleaned up, or workspace state is empty) while file assignments are being submitted.

Common situations: Running `but` file-assignment commands in a repo where the GitButler workspace was just cleaned (all stacks merged); automations firing against an empty workspace; a state desync where workspace loading returned no stacks despite UI showing one.

Understand the failure class

Background: EmptyResultError / "no results found": when an API or scraper succeeds but returns zero rows — this error's family across 9 libraries.

Related errors


AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18). Data as JSON: /api/errors/97a0398d508ee826. Report an issue: GitHub.

Appendix: source

Thrown at crates/but-action/src/simple.rs:70

        context_lines,
    )
    .map_err(|err| serde_error::Error::new(&*err))?;
    if assignments.is_empty() {
        return Ok(Outcome {
            updated_branches: vec![],
        });
    }

    // Get the current stacks in the workspace, creating one if none exists.
    let stacks = stacks_creating_if_none(repo, ws, meta, perm)?;

    // Put the assignments into buckets by stack ID.
    let mut stack_assignments: HashMap<StackId, Vec<DiffSpec>> =
        stacks.iter().map(|s| (s.id, vec![])).collect();
    let default_stack_id = stacks
        .first()
        .map(|s| s.id)
        .ok_or_else(|| anyhow::anyhow!("No stacks found in the workspace"))?;
    for assignment in assignments {
        if let Some(stack_id) = assignment.stack_id {
            stack_assignments
                .entry(stack_id)
                .or_default()
                .push(assignment.into());
        } else if exclusive_stack.is_none() {
            // If there is an exclusive stack. We don't want to do anything with
            // the unassigned changes.
            stack_assignments
                .entry(default_stack_id)
                .or_default()
                .push(assignment.into());
        }
    }
    // Go over the stack_assignments and flatten the diff specs for each stack.
    for (_, specs) in stack_assignments.iter_mut() {
        *specs = but_workspace::flatten_diff_specs(specs.clone());

View on GitHub (pinned to 58e5313667)