{"record":{"id":"9c120b4d73838729","repo":"gastownhall/beads","slug":"not-a-git-repository-w","errorCode":null,"errorMessage":"not a git repository: %w","messagePattern":"not a git repository: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/beads/fingerprint.go","lineNumber":160,"sourceCode":"// GetCloneID generates a unique ID for this specific clone (not shared with other clones)\nfunc GetCloneID() (string, error) {\n\treturn GetCloneIDForPath(\"\")\n}\n\n// GetCloneIDForPath generates a unique ID for the specific clone rooted at or\n// containing repoPath. An empty repoPath uses the current cwd.\n//\n// GH#2867: Uses the main repo root (not worktree root) so that all worktrees\n// sharing a database produce the same clone ID.\nfunc GetCloneIDForPath(repoPath string) (string, error) {\n\thostname, err := os.Hostname()\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to get hostname: %w\", err)\n\t}\n\n\trepoRoot, err := mainRepoRootForPath(repoPath)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"not a git repository: %w\", err)\n\t}\n\n\tnormalizedPath := normalizedRepoPath(repoRoot)\n\thash := sha256.Sum256([]byte(hostname + \":\" + normalizedPath))\n\treturn hex.EncodeToString(hash[:8]), nil\n}\n\nfunc runGitInRepo(repoPath string, args ...string) ([]byte, error) {\n\tcmd := exec.Command(\"git\", args...)\n\tif repoPath != \"\" {\n\t\tcmd.Dir = repoPath\n\t}\n\treturn cmd.Output()\n}\n\n// mainRepoRootForPath returns the main repository root for a given path,\n// correctly handling git worktrees. For worktrees, this returns the parent\n// of --git-common-dir (the main repo root), not --show-toplevel (the","sourceCodeStart":142,"sourceCodeEnd":178,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/beads/fingerprint.go#L142-L178","documentation":"After obtaining the hostname, GetCloneIDForPath resolves the main repository root with mainRepoRootForPath (using --git-common-dir so worktrees share a clone ID, GH#2867). If that resolution fails, the error is wrapped as \"not a git repository\" — the given path is not inside a git work tree or the git command could not run.","triggerScenarios":"Calling GetCloneID/GetCloneIDForPath with a repoPath outside any git repository, a deleted .git directory, or a path where `git rev-parse --show-toplevel --git-common-dir` exits non-zero (e.g. git binary missing or path unreadable).","commonSituations":"Pointing bd at a plain folder (notes, dotfiles dir without git); running before `git clone`/`git init` completed; typo'd path; git not installed or PATH broken so the exec fails.","solutions":["Verify with `git -C <path> rev-parse --show-toplevel`; if it fails, run `git init` or clone the repo first","Pass the correct repository path to GetCloneIDForPath","Ensure git is installed and on PATH (`which git`)","Restore a missing .git directory or re-clone"],"exampleFix":"// before\ncloneID, err := beads.GetCloneIDForPath(\"/tmp/scratch\")\n// after\ncloneID, err := beads.GetCloneIDForPath(\"/home/me/project\") // inside a git repo\n","handlingStrategy":"validation","validationCode":"if out, err := exec.Command(\"git\", \"-C\", path, \"rev-parse\", \"--is-inside-work-tree\").Output(); err != nil || strings.TrimSpace(string(out)) != \"true\" {\n    // not a repo; init or clone before calling\n}","typeGuard":null,"tryCatchPattern":"cloneID, err := beads.GetCloneIDForPath(path)\nif err != nil && strings.Contains(err.Error(), \"not a git repository\") {\n    return fmt.Errorf(\"initialize the repo first: %w\", err)\n}","preventionTips":["Verify the target path is inside a git work tree before computing clone IDs","Ensure git is installed and on PATH","Pass explicit repo paths instead of relying on ambient CWD","Restore missing .git directories promptly"],"tags":["git","clone-id","repository"],"backgroundTag":"not-a-git-repository","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}