gastownhall/beads · warning
unexpected git rev-parse output
Error message
unexpected git rev-parse output
What it means
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.
Source
Thrown at internal/beads/fingerprint.go:196
// of --git-common-dir (the main repo root), not --show-toplevel (the
// worktree root). For regular repos, both are equivalent.
//
// GH#2867: This ensures fingerprint computation uses a stable path that is
// the same across all worktrees sharing a database.
func mainRepoRootForPath(repoPath string) (string, error) {
// Get both toplevel and common-dir in one pass to detect worktrees.
cmd := exec.Command("git", "rev-parse", "--show-toplevel", "--git-common-dir")
if repoPath != "" {
cmd.Dir = repoPath
}
output, err := cmd.Output()
if err != nil {
return "", fmt.Errorf("not a git repository: %w", err)
}
lines := strings.SplitN(strings.TrimSpace(string(output)), "\n", 2)
if len(lines) < 2 {
return "", fmt.Errorf("unexpected git rev-parse output")
}
toplevel := strings.TrimSpace(lines[0])
commonDir := strings.TrimSpace(lines[1])
// Resolve to absolute paths for comparison.
absToplevel, err := filepath.Abs(toplevel)
if err != nil {
return toplevel, nil
}
// commonDir may be relative; resolve relative to the working directory
// (repoPath if set, else CWD).
if !filepath.IsAbs(commonDir) {
base := repoPath
if base == "" {
base, _ = os.Getwd()
}View on GitHub (pinned to 71377f2769)
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
Example fix
// before (inside bare repo) cd /srv/repo.git && bd ... // after cd /srv/repo-worktree && bd ...
Defensive patterns
Strategy: fallback
Validate before calling
out, err := exec.Command("git", "-C", path, "rev-parse", "--show-toplevel", "--git-common-dir").Output()
if err != nil || len(strings.SplitN(strings.TrimSpace(string(out)), "\n", 2)) < 2 {
// output shape unexpected; run from a normal work tree
} Try / catch
root, err := beads.ComputeRepoIDForPath(path)
if err != nil && strings.Contains(err.Error(), "unexpected git rev-parse output") {
return fmt.Errorf("run from inside a normal (non-bare) work tree: %w", err)
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- failed to untrack redirect file: %w
- failed to untrack last-touched file: %w
- failed to untrack files: %w %s
- failed to init git in planning repo: %w
- unexpected porcelain status record %q
AI-assisted analysis of gastownhall/beads@71377f2769 (2026-08-30).
Data as JSON: /api/errors/1c08d67afc5a6d58.
Report an issue: GitHub.