{"record":{"id":"bc28f917dac6db63","repo":"gitbutlerapp/gitbutler","slug":"no-git-directory-found-in-repository","errorCode":null,"errorMessage":"no .git directory found in repository","messagePattern":"no \\.git directory found in repository","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/gitbutler-project/src/project.rs","lineNumber":331,"sourceCode":"\n    /// Try to get the `Project`, returning an error if it was not added.\n    pub fn try_project(self) -> anyhow::Result<Project> {\n        match self {\n            AddProjectOutcome::Added(p) => Ok(p),\n            AddProjectOutcome::AlreadyExists(_) => Err(anyhow::anyhow!(\"project already exists\")),\n            AddProjectOutcome::PathNotFound => Err(anyhow::anyhow!(\"project path not found\")),\n            AddProjectOutcome::NotADirectory => {\n                Err(anyhow::anyhow!(\"project path is not a directory\"))\n            }\n            AddProjectOutcome::BareRepository => {\n                Err(anyhow::anyhow!(\"bare repositories are not supported\"))\n            }\n            AddProjectOutcome::NonMainWorktree => {\n                Err(anyhow::anyhow!(\"non-main worktrees are not supported\"))\n            }\n            AddProjectOutcome::NoWorkdir => Err(anyhow::anyhow!(\"no workdir found for repository\")),\n            AddProjectOutcome::NoDotGitDirectory => {\n                Err(anyhow::anyhow!(\"no .git directory found in repository\"))\n            }\n            AddProjectOutcome::ReftableRefFormatUnsupported => Err(anyhow::anyhow!(\n                \"unsupported repository reference format: reftable\"\n            )),\n            AddProjectOutcome::NotAGitRepository(msg) => {\n                Err(anyhow::anyhow!(\"not a git repository: {msg}\"))\n            }\n        }\n    }\n}\n","sourceCodeStart":313,"sourceCodeEnd":342,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/gitbutler-project/src/project.rs#L313-L342","documentation":"gitbutler-project's try_project() validates a directory before adding it as a project. If the repository discovery (AddProjectOutcome::NoDotGitDirectory) finds no .git directory, the project cannot be tracked, so this anyhow error is returned. GitButler requires the repo to have a .git directory to store its metadata.","triggerScenarios":"Calling try_project (or the project-add API path that calls it) on a path that resolves to a git repository without a .git directory at the expected location — e.g. bare repositories, reftable/odd layouts, or a path whose discovery concluded no .git exists.","commonSituations":"Pointing GitButler at a bare clone; a partially deleted or corrupted .git directory; symlinked worktrees where .git resolution fails; adding a folder that was assumed to be a checkout but never was cloned.","solutions":["Verify the directory is a proper non-bare git checkout (a .git entry exists and is a directory).","Re-clone the repository if .git is missing or corrupted.","If using a linked worktree, open the main worktree instead — non-main worktrees are separately rejected.","Ensure the path passed to add-project is the worktree root, not a subdirectory or the .git folder itself."],"exampleFix":"// before\nadd_project(\"/srv/myrepo.git\")           // bare repo, no .git dir\n// after\ngit clone /srv/myrepo.git ~/work/myrepo\nadd_project(\"~/work/myrepo\")             // non-bare checkout with .git","handlingStrategy":"validation","validationCode":"const path = '/srv/myrepo';\nif (!fs.existsSync(pathJoin(path, '.git'))) {\n  throw new Error(`${path} has no .git directory; cannot add as project`);\n}","typeGuard":"const isGitCheckout = (p) => fs.existsSync(pathJoin(p, '.git')) && fs.statSync(pathJoin(p, '.git')).isDirectory();","tryCatchPattern":null,"preventionTips":["Only add non-bare checkouts as projects.","Check for .git existence before programmatic project creation.","Avoid operating on linked worktrees with GitButler."],"tags":["git","project-setup","validation"],"backgroundTag":"directory-not-found","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"}