{"record":{"id":"ea68ac3d5b17ddc6","repo":"gastownhall/beads","slug":"not-in-a-git-repository","errorCode":null,"errorMessage":"not in a git repository","messagePattern":"not in a git repository","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/hooks.go","lineNumber":1288,"sourceCode":"\t// v9: `. \"$(dirname \"$0\")/h\"`  (or with `--` / single quotes).\n\t// Require both `dirname` and a trailing `/h\"` or `/h'` to avoid matching\n\t// unrelated sourcing of files that happen to end in \"h\".\n\tif strings.Contains(line, \"dirname\") && (strings.HasSuffix(line, `/h\"`) || strings.HasSuffix(line, `/h'`) || strings.HasSuffix(line, \"/h\")) {\n\t\treturn true\n\t}\n\treturn false\n}\n\nfunc configureSharedHooksPath() error {\n\t// Set git config core.hooksPath to an absolute path pointing to .beads-hooks.\n\t// Using an absolute path is critical for git worktrees (GH#2414):\n\t// git resolves relative core.hooksPath relative to the working tree root.\n\trepoRoot, _ := git.GetMainRepoRoot()\n\tif repoRoot == \"\" {\n\t\trepoRoot = git.GetRepoRoot()\n\t}\n\tif repoRoot == \"\" {\n\t\treturn fmt.Errorf(\"not in a git repository\")\n\t}\n\tabsHooksPath := filepath.Join(repoRoot, \".beads-hooks\")\n\tcmd := exec.Command(\"git\", \"config\", \"core.hooksPath\", absHooksPath)\n\tcmd.Dir = repoRoot\n\tif output, err := cmd.CombinedOutput(); err != nil {\n\t\treturn fmt.Errorf(\"git config failed: %w (output: %s)\", err, string(output))\n\t}\n\treturn nil\n}\n\nfunc configureBeadsHooksPath() error {\n\t// Set git config core.hooksPath to an absolute path pointing to .beads/hooks.\n\t// Using an absolute path is critical for git worktrees (GH#2414):\n\t// git resolves relative core.hooksPath relative to the working tree root,\n\t// so in a worktree \".beads/hooks\" would resolve to <worktree>/.beads/hooks/\n\t// which doesn't exist — the hooks live in the main repo's .beads/hooks/.\n\trepoRoot, _ := git.GetMainRepoRoot()\n\tif repoRoot == \"\" {","sourceCodeStart":1270,"sourceCodeEnd":1306,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/hooks.go#L1270-L1306","documentation":"configureSharedHooksPath sets core.hooksPath to <repoRoot>/.beads-hooks and needs a repository root to anchor it (git resolves relative hooks paths against the work tree root, hence the absolute path). It tries git.GetMainRepoRoot() then git.GetRepoRoot(); when both are empty it fails with `not in a git repository`.","triggerScenarios":"installHooksWithOptions (shared mode) calls configureSharedHooksPath from a directory where git cannot find a work tree — no .git anywhere up the tree, GIT_DIR pointing nowhere, or an uninitialized repo.","commonSituations":"Running `bd hooks install --shared` in a temp directory or home dir outside any repo; running before `git init`; CI steps that download sources without the .git directory.","solutions":["Run `git init` if the directory should be a repository, then re-run the bd command","cd into the actual repository root and re-run `bd hooks install --shared`","Verify `git rev-parse --show-toplevel` succeeds from your current directory","If in CI without .git, fetch the full checkout (git fetch / clone) before installing hooks"],"exampleFix":"// before\n$ cd /tmp/proj-src && bd hooks install --shared\nnot in a git repository\n// after\n$ git init && bd hooks install --shared","handlingStrategy":"validation","validationCode":"git rev-parse --show-toplevel >/dev/null 2>&1 && echo ok || echo 'not a git repository — run git init or cd into the repo'","typeGuard":null,"tryCatchPattern":"if err := installHooksWithOptions(names, false, true, false, false); err != nil { if strings.Contains(err.Error(), \"not in a git repository\") { /* run git init or change directory, then retry */ } }","preventionTips":["Confirm `git rev-parse --show-toplevel` works before shared hook installs","Run `git init` before bd setup in brand-new projects","In CI, use a full git clone (not an exported tarball) when installing hooks"],"tags":["git","repository","hooks-path"],"backgroundTag":"not-a-git-repository","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}