{"record":{"id":"1c08d67afc5a6d58","repo":"gastownhall/beads","slug":"unexpected-git-rev-parse-output-1c08d6","errorCode":null,"errorMessage":"unexpected git rev-parse output","messagePattern":"unexpected git rev-parse output","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"internal/beads/fingerprint.go","lineNumber":196,"sourceCode":"// of --git-common-dir (the main repo root), not --show-toplevel (the\n// worktree root). For regular repos, both are equivalent.\n//\n// GH#2867: This ensures fingerprint computation uses a stable path that is\n// the same across all worktrees sharing a database.\nfunc mainRepoRootForPath(repoPath string) (string, error) {\n\t// Get both toplevel and common-dir in one pass to detect worktrees.\n\tcmd := exec.Command(\"git\", \"rev-parse\", \"--show-toplevel\", \"--git-common-dir\")\n\tif repoPath != \"\" {\n\t\tcmd.Dir = repoPath\n\t}\n\toutput, err := cmd.Output()\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"not a git repository: %w\", err)\n\t}\n\n\tlines := strings.SplitN(strings.TrimSpace(string(output)), \"\\n\", 2)\n\tif len(lines) < 2 {\n\t\treturn \"\", fmt.Errorf(\"unexpected git rev-parse output\")\n\t}\n\n\ttoplevel := strings.TrimSpace(lines[0])\n\tcommonDir := strings.TrimSpace(lines[1])\n\n\t// Resolve to absolute paths for comparison.\n\tabsToplevel, err := filepath.Abs(toplevel)\n\tif err != nil {\n\t\treturn toplevel, nil\n\t}\n\n\t// commonDir may be relative; resolve relative to the working directory\n\t// (repoPath if set, else CWD).\n\tif !filepath.IsAbs(commonDir) {\n\t\tbase := repoPath\n\t\tif base == \"\" {\n\t\t\tbase, _ = os.Getwd()\n\t\t}","sourceCodeStart":178,"sourceCodeEnd":214,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/beads/fingerprint.go#L178-L214","documentation":"mainRepoRootForPath expects `git rev-parse --show-toplevel --git-common-dir` to print exactly two lines: the toplevel and the common dir. If the trimmed output splits into fewer than two lines, bd returns \"unexpected git rev-parse output\" — git succeeded but its output shape was not what this code contractually expects.","triggerScenarios":"git rev-parse succeeds but emits a single line or empty output — e.g. run inside .git dir or bare repo where toplevel is empty/absent, unusual git versions/config (quotePath, aliases), or a wrapper script replacing git with different output.","commonSituations":"Running from inside the .git directory or a bare repository; a global git alias/shim intercepting rev-parse; heavily modified GIT_* environment variables; very old or patched git builds with different multi-command rev-parse behavior.","solutions":["Run from inside a normal (non-bare) work tree instead of the .git directory or a bare repo","Test `git rev-parse --show-toplevel --git-common-dir` manually in the affected path and compare output","Remove git aliases/shims or GIT_* env overrides (GIT_DIR, GIT_WORK_TREE) that alter rev-parse output","Upgrade/downgrade to a standard git version and retry"],"exampleFix":"// before (inside bare repo)\ncd /srv/repo.git && bd ...\n// after\ncd /srv/repo-worktree && bd ...\n","handlingStrategy":"fallback","validationCode":"out, err := exec.Command(\"git\", \"-C\", path, \"rev-parse\", \"--show-toplevel\", \"--git-common-dir\").Output()\nif err != nil || len(strings.SplitN(strings.TrimSpace(string(out)), \"\\n\", 2)) < 2 {\n    // output shape unexpected; run from a normal work tree\n}","typeGuard":null,"tryCatchPattern":"root, err := beads.ComputeRepoIDForPath(path)\nif err != nil && strings.Contains(err.Error(), \"unexpected git rev-parse output\") {\n    return fmt.Errorf(\"run from inside a normal (non-bare) work tree: %w\", err)\n}","preventionTips":["Run bd from a regular work tree, not inside .git or a bare repo","Unset GIT_DIR/GIT_WORK_TREE and remove git shims/aliases that alter rev-parse","Pin a standard git version in CI images","Manually verify `git rev-parse --show-toplevel --git-common-dir` prints two lines in the target path"],"tags":["git","exec","parsing"],"backgroundTag":"unexpected-git-output","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}