fix: support git worktrees in hooks installation

Use `git rev-parse --git-dir` instead of hardcoded `.git` path to find
the actual git directory. In worktrees, `.git` is a file containing a
gitdir pointer, not a directory.

Changes:
- Add getGitDir() helper in hooks.go
- Update installHooks(), uninstallHooks(), CheckGitHooks() to use it
- Update hooksInstalled(), detectExistingHooks(), installGitHooks() in init.go
- Update checkHooksQuick() in doctor.go
- Update GitHooks() in doctor/fix/hooks.go
- Update tests to use real git repos via `git init`

Fixes bd-63l

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Steve Yegge
2025-11-29 23:19:57 -08:00
parent fa9285a663
commit 0b13a0df3c
7 changed files with 127 additions and 58 deletions

View File

@@ -4,7 +4,6 @@ import (
"fmt"
"os"
"os/exec"
"path/filepath"
)
// GitHooks fixes missing or broken git hooks by calling bd hooks install
@@ -14,9 +13,11 @@ func GitHooks(path string) error {
return err
}
// Check if we're in a git repository
gitDir := filepath.Join(path, ".git")
if _, err := os.Stat(gitDir); os.IsNotExist(err) {
// Check if we're in a git repository using git rev-parse
// This handles worktrees where .git is a file, not a directory
checkCmd := exec.Command("git", "rev-parse", "--git-dir")
checkCmd.Dir = path
if err := checkCmd.Run(); err != nil {
return fmt.Errorf("not a git repository")
}