{"record":{"id":"203b8b3cb52110b7","repo":"GitoxideLabs/gitoxide","slug":"need-a-worktree-to-clean-this-is-a-bare-repositor","errorCode":null,"errorMessage":"Need a worktree to clean, this is a bare repository","messagePattern":"Need a worktree to clean, this is a bare repository","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"gitoxide-core/src/repository/clean.rs","lineNumber":63,"sourceCode":"        patterns: Vec<BString>,\n        Options {\n            debug,\n            format,\n            mut execute,\n            ignored,\n            precious,\n            directories,\n            repositories,\n            skip_hidden_repositories,\n            find_untracked_repositories,\n            pathspec_matches_result,\n        }: Options,\n    ) -> anyhow::Result<()> {\n        if format != OutputFormat::Human {\n            bail!(\"JSON output isn't implemented yet\");\n        }\n        let Some(workdir) = repo.workdir() else {\n            bail!(\"Need a worktree to clean, this is a bare repository\");\n        };\n\n        let index = repo.index_or_empty()?;\n        let pathspec_for_dirwalk = !pathspec_matches_result;\n        let has_patterns = !patterns.is_empty();\n        let mut collect = InterruptibleCollect::default();\n        let collapse_directories = CollapseDirectory;\n        let options = repo\n            .dirwalk_options()?\n            .emit_pruned(true)\n            .for_deletion(if (ignored || precious) && directories {\n                match skip_hidden_repositories {\n                    Some(FindRepository::NonBare) => Some(FindNonBareRepositoriesInIgnoredDirectories),\n                    Some(FindRepository::All) => Some(FindRepositoriesInIgnoredDirectories),\n                    None => Some(Default::default()),\n                }\n            } else {\n                Some(Default::default())","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/GitoxideLabs/gitoxide/blob/e73179060badf27222d790981fac3f84c1830a7e/gitoxide-core/src/repository/clean.rs#L45-L81","documentation":"`clean` cannot operate on a bare repository because there is no working tree whose untracked files could be removed. The function destructures `repo.workdir()` and bails when it is `None` (bare repo).","triggerScenarios":"Calling `clean` with a `gix::Repository` handle opened from (or pointing into) a bare repository — e.g. `gix::open(\"repo.git\")` or `gix::discover` landing on a bare repo.","commonSituations":"Opening the repository via a bare `GIT_DIR`, discovering from a hook or server-side path, accidentally pointing the CLI at `something.git` instead of the working clone.","solutions":["Run clean against a non-bare clone that has a worktree","If you meant the bare repo's files, operate on the filesystem directly rather than using `clean`","Verify with `repo.workdir().is_some()` before calling and surface a clearer message to the user"],"exampleFix":"// before\nclean(repo, options, format, progress, &mut out)?;\n// after\nif repo.workdir().is_none() {\n    anyhow::bail!(\"refusing to clean: repository is bare\");\n}\nclean(repo, options, format, progress, &mut out)?;","handlingStrategy":"validation","validationCode":"if repo.workdir().is_none() {\n    anyhow::bail!(\"cannot clean: bare repository has no worktree\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check `repo.is_bare()` / `repo.workdir()` before worktree-dependent operations","Ensure discovery starts inside a working clone, not the bare dir"],"tags":["git","bare-repository","worktree"],"backgroundTag":"unsupported-operation","analyzedSha":"e73179060badf27222d790981fac3f84c1830a7e","analyzedAt":"2026-09-08T11:26:50.865Z","contentChangedAt":"2026-09-08T11:26:50.865Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}