{"record":{"id":"f93e5c9d9eecc1a5","repo":"gastownhall/beads","slug":"unexpected-git-rev-parse-output","errorCode":null,"errorMessage":"unexpected git rev-parse output","messagePattern":"unexpected git rev-parse output","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/doctor/hooks_migration.go","lineNumber":297,"sourceCode":"\t\tif strings.Contains(lower, \"bd\") || strings.Contains(lower, \"beads\") {\n\t\t\treturn true\n\t\t}\n\t}\n\n\treturn false\n}\n\nfunc resolveGitHooksDir(path string) (repoRoot string, hooksDir string, err error) {\n\tcmd := exec.Command(\"git\", \"rev-parse\", \"--show-toplevel\", \"--git-common-dir\")\n\tcmd.Dir = path\n\tout, err := cmd.Output()\n\tif err != nil {\n\t\treturn \"\", \"\", err\n\t}\n\n\tlines := strings.Split(strings.TrimSpace(string(out)), \"\\n\")\n\tif len(lines) < 2 {\n\t\treturn \"\", \"\", fmt.Errorf(\"unexpected git rev-parse output\")\n\t}\n\n\trepoRoot = strings.TrimSpace(lines[0])\n\tgitCommonDir := strings.TrimSpace(lines[1])\n\tif !filepath.IsAbs(gitCommonDir) {\n\t\tgitCommonDir = filepath.Join(repoRoot, gitCommonDir)\n\t}\n\n\thooksDir = filepath.Join(gitCommonDir, \"hooks\")\n\n\thooksPathCmd := exec.Command(\"git\", \"config\", \"--get\", \"core.hooksPath\")\n\thooksPathCmd.Dir = repoRoot\n\tif hooksPathOut, hooksPathErr := hooksPathCmd.Output(); hooksPathErr == nil {\n\t\thooksPath := strings.TrimSpace(string(hooksPathOut))\n\t\tif hooksPath != \"\" {\n\t\t\thooksPath = expandHookPathTilde(hooksPath)\n\t\t\tif !filepath.IsAbs(hooksPath) {\n\t\t\t\thooksPath = filepath.Join(repoRoot, hooksPath)","sourceCodeStart":279,"sourceCodeEnd":315,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/doctor/hooks_migration.go#L279-L315","documentation":"resolveGitHooksDir shells out to 'git rev-parse' expecting exactly two lines of output: the repo root and the git common dir. If the trimmed output has fewer than two lines, the function cannot locate the hooks directory and returns this error. It indicates git did not answer in the expected format, usually because the target is not inside a git worktree.","triggerScenarios":"git rev-parse --git-common-dir --show-toplevel (as invoked by resolveGitHooksDir) prints fewer than 2 newline-separated lines — typically because the path is not a git repository, so rev-parse fails or prints one line / nothing.","commonSituations":"Running bd doctor hook migration outside any git repo; inside a bare repo where --show-toplevel is empty; a broken .git directory; an ancient git version emitting different output; GIT_DIR/GIT_WORK_TREE env vars pointing somewhere invalid.","solutions":["Run the command from inside a git worktree (git rev-parse --is-inside-work-tree should say true).","Check git is installed and reasonably current: git --version; upgrade if very old.","Inspect unset or wrong GIT_DIR / GIT_WORK_TREE environment variables and remove them if unintended.","Verify the repo is not bare/corrupt: ls .git and run git status to confirm it is healthy."],"exampleFix":"// before\n$ cd ~/not-a-repo && bd doctor hooks --plan .\nError: unexpected git rev-parse output\n// after\n$ cd /path/to/repo && bd doctor hooks --plan .\n✓ migration plan built","handlingStrategy":"validation","validationCode":"out, err := exec.Command(\"git\", \"-C\", path, \"rev-parse\", \"--is-inside-work-tree\").Output()\nif err != nil || strings.TrimSpace(string(out)) != \"true\" {\n    return fmt.Errorf(\"%s is not inside a git worktree\", path)\n}","typeGuard":null,"tryCatchPattern":"plan, err := doctor.PlanHookMigration(path)\nif err != nil && strings.Contains(err.Error(), \"unexpected git rev-parse output\") {\n    // not a git repo (or broken .git): surface a friendly message\n    return fmt.Errorf(\"%s is not a usable git repository\", path)\n}","preventionTips":["Run hook-migration commands only inside a git worktree.","Sanity-check with git rev-parse --is-inside-work-tree before scripting.","Unset stray GIT_DIR / GIT_WORK_TREE variables in CI environments.","Keep git installed and reasonably up to date."],"tags":["git","git-hooks","parse"],"backgroundTag":"not-a-git-repository","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}