gitbutlerapp/gitbutler · error

Worktree is archived

Error message

Worktree {name} is archived

What it means

`active_worktree` looks up a linked worktree by name and rejects archived ones. Archiving is a soft delete: the worktree record still exists, so the lookup succeeds, but operating on its changes (via `open_changes_source`) is refused because the checkout is no longer active.

Solutions

  1. Un-archive the worktree (re-create it or clear the archived flag) before reading its changes
  2. Pick a different, non-archived worktree as the change source
  3. Refresh the worktree listing and filter out archived entries before choosing a source

Example fix

// before
await api.openChangesSource(ctx, 'feature-x'); // archived
// after
const wt = (await api.worktreesList(ctx)).find(w => w.name === 'feature-x');
if (wt && !wt.archived) await api.openChangesSource(ctx, 'feature-x');
Defensive patterns

Strategy: validation

Validate before calling

const wt = worktrees.find(w => w.name === name);
if (!wt) throw new Error('Worktree does not exist');
if (wt.archived) throw new Error('Worktree is archived; un-archive it first');

Type guard

const isActive = (w: Worktree): w is Worktree & { archived: false } => !w.archived;

Try / catch

try {
  await api.openChangesSource(ctx, name);
} catch (e) {
  if (e.message.includes('is archived')) await unarchiveOrPickOtherWorktree(name);
}

Prevention

When it happens

Trigger: Calling `open_changes_source` with a `source` name that resolves to a worktree whose `worktree.archived` is `true`.

Common situations: A UI or script holds a stale worktree reference after the user archived it in another session; automation targets a worktree by old name that has since been archived; retry logic re-targets an archived worktree.

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


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

Appendix: source

Thrown at crates/but-api/src/worktrees.rs:94

    }
    Ok(())
}

/// Look up the *active* linked worktree named `name`.
///
/// Every command here operates on active worktrees only - an archived one is
/// hidden from the graph, so operations against it could not be materialized.
///
/// Must not be called while a database handle is borrowed, see
/// [`but_ctx::Context::worktrees_with_state()`].
fn active_worktree(ctx: &but_ctx::Context, name: &str) -> Result<WorktreeEntry> {
    let worktree = ctx
        .worktrees_with_state()?
        .into_iter()
        .find(|worktree| worktree.name == name.as_bytes())
        .with_context(|| format!("Worktree {name} does not exist"))?;
    if worktree.archived {
        bail!("Worktree {name} is archived");
    }
    if ctx.worktree_head(worktree.name.as_bstr())?.is_none() {
        // Unborn, workspace-ref checkout, or broken - nothing to operate on.
        bail!("Worktree {name} has no usable HEAD");
    }
    Ok(worktree)
}

/// Open the checkout that `source` reads its changes from, returning its stable
/// name along with a plain from-disk open of it, or `None` for the main worktree.
///
/// Callers turn this into a [`ChangeSource`](but_workspace::commit::ChangeSource)
/// for the duration of an editor-backed operation.
///
/// Must not be called while a database handle is borrowed, see
/// [`but_ctx::Context::worktrees_with_state()`].
pub(crate) fn open_changes_source(
    ctx: &but_ctx::Context,

View on GitHub (pinned to 58e5313667)