{"record":{"id":"1663bc71d1938170","repo":"gitbutlerapp/gitbutler","slug":"worktree-name-is-archived","errorCode":null,"errorMessage":"Worktree {name} is archived","messagePattern":"Worktree (.+?) is archived","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but-api/src/worktrees.rs","lineNumber":94,"sourceCode":"    }\n    Ok(())\n}\n\n/// Look up the *active* linked worktree named `name`.\n///\n/// Every command here operates on active worktrees only - an archived one is\n/// hidden from the graph, so operations against it could not be materialized.\n///\n/// Must not be called while a database handle is borrowed, see\n/// [`but_ctx::Context::worktrees_with_state()`].\nfn active_worktree(ctx: &but_ctx::Context, name: &str) -> Result<WorktreeEntry> {\n    let worktree = ctx\n        .worktrees_with_state()?\n        .into_iter()\n        .find(|worktree| worktree.name == name.as_bytes())\n        .with_context(|| format!(\"Worktree {name} does not exist\"))?;\n    if worktree.archived {\n        bail!(\"Worktree {name} is archived\");\n    }\n    if ctx.worktree_head(worktree.name.as_bstr())?.is_none() {\n        // Unborn, workspace-ref checkout, or broken - nothing to operate on.\n        bail!(\"Worktree {name} has no usable HEAD\");\n    }\n    Ok(worktree)\n}\n\n/// Open the checkout that `source` reads its changes from, returning its stable\n/// name along with a plain from-disk open of it, or `None` for the main worktree.\n///\n/// Callers turn this into a [`ChangeSource`](but_workspace::commit::ChangeSource)\n/// for the duration of an editor-backed operation.\n///\n/// Must not be called while a database handle is borrowed, see\n/// [`but_ctx::Context::worktrees_with_state()`].\npub(crate) fn open_changes_source(\n    ctx: &but_ctx::Context,","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but-api/src/worktrees.rs#L76-L112","documentation":"`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.","triggerScenarios":"Calling `open_changes_source` with a `source` name that resolves to a worktree whose `worktree.archived` is `true`.","commonSituations":"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.","solutions":["Un-archive the worktree (re-create it or clear the archived flag) before reading its changes","Pick a different, non-archived worktree as the change source","Refresh the worktree listing and filter out archived entries before choosing a source"],"exampleFix":"// before\nawait api.openChangesSource(ctx, 'feature-x'); // archived\n// after\nconst wt = (await api.worktreesList(ctx)).find(w => w.name === 'feature-x');\nif (wt && !wt.archived) await api.openChangesSource(ctx, 'feature-x');","handlingStrategy":"validation","validationCode":"const wt = worktrees.find(w => w.name === name);\nif (!wt) throw new Error('Worktree does not exist');\nif (wt.archived) throw new Error('Worktree is archived; un-archive it first');","typeGuard":"const isActive = (w: Worktree): w is Worktree & { archived: false } => !w.archived;","tryCatchPattern":"try {\n  await api.openChangesSource(ctx, name);\n} catch (e) {\n  if (e.message.includes('is archived')) await unarchiveOrPickOtherWorktree(name);\n}","preventionTips":["Refresh the worktree listing and filter out archived entries before use","Invalidate cached worktree references after archive operations","Listen for archive events and update stored source names"],"tags":["worktree","archived","invalid-state"],"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"}