{"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":987,"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":969,"sourceCodeEnd":1005,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/2497b8007aa4a1922dae9a805b32ffe5b5037785/crates/but-ctx/src/lib.rs#L969-L1005","documentation":"Context::workdir_or_fail returns the repository's worktree root and fails on bare repositories, where gix's workdir() is None (core.bare = true, or the path is a .git directory itself). The doc comment on the method says 'Try to gracefully degrade if there is no worktree!' — the Option-returning workdir() exists precisely for call sites that can operate without a checkout; this _or_fail variant is for code that fundamentally needs a working tree (index, status, writing files).","triggerScenarios":"Creating a but Context for a bare clone (git clone --bare), a .git directory, or a repo with core.bare=true, then invoking any API that internally calls workdir_or_fail — workspace operations, file open/diff, status.","commonSituations":"Automation pointing at repo.git instead of repo; mirror clones; CI operating on bare checkouts; users selecting the wrong folder in a picker.","solutions":["Open the non-bare working clone instead of the bare repository.","If bare repos must be handled, branch on ctx.workdir()? and restrict to read-only tree queries.","When accepting user-supplied paths, check core.bare in .git/config up front and reject with guidance."],"exampleFix":"// before\nlet workdir = ctx.workdir_or_fail()?;\n\n// after\nmatch ctx.workdir()? {\n    Some(dir) => { /* normal path */ }\n    None => anyhow::bail!(\"bare repository has no worktree; open the working clone instead\"),\n}","handlingStrategy":"validation","validationCode":"if ctx.workdir()?.is_none() {\n    anyhow::bail!(\"this operation needs a worktree; bare repositories are unsupported\");\n}","typeGuard":"fn has_worktree(ctx: &Context) -> bool {\n    ctx.workdir().ok().flatten().is_some()\n}","tryCatchPattern":null,"preventionTips":["Validate the chosen folder is a non-bare clone before creating the Context.","In folder pickers, filter out *.git directories and bare clones.","Prefer the Option-returning workdir() wherever the flow can degrade gracefully."],"tags":["git","bare-repository","worktree","filesystem","setup"],"backgroundTag":"bare-repository-no-worktree","analyzedSha":"2497b8007aa4a1922dae9a805b32ffe5b5037785","analyzedAt":"2026-08-17T00:30:25.648Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}