{"record":{"id":"0f2b5fc6b7594131","repo":"gitbutlerapp/gitbutler","slug":"cannot-currently-work-in-repositories-without-a-wo","errorCode":null,"errorMessage":"Cannot currently work in repositories without a worktree","messagePattern":"Cannot currently work in repositories without a worktree","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but-ctx/src/lib.rs","lineNumber":1002,"sourceCode":"    /// Fallible as it may need to open a repository.\n    pub fn workdir_or_gitdir(&self) -> anyhow::Result<PathBuf> {\n        let repo = self.repo.get()?;\n        Ok(repo.workdir().unwrap_or(repo.git_dir()).to_owned())\n    }\n\n    /// Return the worktree directory associated with the context Git [repository](Self::repo).\n    pub fn workdir(&self) -> anyhow::Result<Option<PathBuf>> {\n        self.repo.get().map(|repo| repo.workdir().map(Into::into))\n    }\n\n    /// Return the worktree directory associated with the context Git [repository](Self::repo),\n    /// or fail.\n    ///\n    /// # Try to gracefully degrade if there is no worktree!\n    pub fn workdir_or_fail(&self) -> anyhow::Result<PathBuf> {\n        let repo = self.repo.get()?;\n        repo.workdir()\n            .ok_or_else(|| anyhow!(\"Cannot currently work in repositories without a worktree\"))\n            .map(Into::into)\n    }\n}\n\n/// *Repository* helpers, for when you need something more specific than [Self::repo].\nimpl Context {\n    /// Open an isolated repository, one that didn't read options beyond `.git/config` and\n    /// knows no environment variables.\n    ///\n    /// Use it for fastest-possible access, when incomplete configuration is acceptable.\n    /// Note that [Self::repo].get() should be preferred.\n    pub fn open_isolated_repo(&self) -> anyhow::Result<gix::Repository> {\n        Ok(gix::open_opts(\n            &self.gitdir,\n            gix::open::Options::isolated(),\n        )?)\n    }\n","sourceCodeStart":984,"sourceCodeEnd":1020,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but-ctx/src/lib.rs#L984-L1020","documentation":"Context::workdir_or_fail returns the repository's working directory, but bare repositories have none. The library cannot run worktree-dependent operations (file lookups, workspace commands) without a checkout, so it raises this anyhow error with code NOT_AUTHENTICATED-style plain message. It exists precisely to fail fast with a clear message instead of returning None.","triggerScenarios":"Calling workdir_or_fail (via set_active, handle_command_confirm, find_files, etc.) on a Context whose repository is bare (repo.workdir() returns None) — e.g. pointing but at a bare repo path or a repo opened via gitdir.","commonSituations":"Running `but` commands inside a bare repository or a --bare clone; automation that opens the .git directory directly; server-side repo paths without a checkout.","solutions":["Use a non-bare working clone of the repository","If you must work with a bare repo, clone it to a working directory first and point but there","Guard calls with a check for a worktree (repo.workdir().is_some()) and skip worktree-dependent operations otherwise"],"exampleFix":"// before\nlet dir = ctx.workdir_or_fail()?;\nfind_files(&ctx)?;\n// after\nlet dir = match ctx.repo.get()?.workdir() {\n    Some(_) => ctx.workdir_or_fail()?,\n    None => anyhow::bail!(\"this command needs a checked-out worktree\"),\n};","handlingStrategy":"fallback","validationCode":"if ctx.repo.get()?.workdir().is_none() {\n    bail!(\"operation requires a checked-out worktree\");\n}","typeGuard":"fn has_worktree(ctx: &Context) -> bool { ctx.repo.get().ok().and_then(|r| r.workdir()).is_some() }","tryCatchPattern":"match ctx.workdir_or_fail() {\n    Ok(dir) => use(dir),\n    Err(e) if e.to_string().contains(\"without a worktree\") => clone_working_copy()?,\n    Err(e) => return Err(e),\n}","preventionTips":["Never point but at bare repositories or bare --git-dir paths","Clone with a working tree for interactive/worktree operations","Skip worktree-dependent features in server-side automation"],"tags":["git","worktree","bare-repository"],"backgroundTag":"unsupported-operation","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"}