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:
@@ -371,9 +371,21 @@ func checkSyncBranchQuickDB(db *sql.DB) string {
|
||||
// checkHooksQuick does a fast check for outdated git hooks.
|
||||
// Checks all beads hooks: pre-commit, post-merge, pre-push, post-checkout (bd-2em).
|
||||
func checkHooksQuick(path string) string {
|
||||
hooksDir := filepath.Join(path, ".git", "hooks")
|
||||
// Get actual git directory (handles worktrees where .git is a file)
|
||||
cmd := exec.Command("git", "rev-parse", "--git-dir")
|
||||
cmd.Dir = path
|
||||
output, err := cmd.Output()
|
||||
if err != nil {
|
||||
return "" // Not a git repo, skip
|
||||
}
|
||||
gitDir := strings.TrimSpace(string(output))
|
||||
// Make absolute if relative
|
||||
if !filepath.IsAbs(gitDir) {
|
||||
gitDir = filepath.Join(path, gitDir)
|
||||
}
|
||||
hooksDir := filepath.Join(gitDir, "hooks")
|
||||
|
||||
// Check if .git/hooks exists
|
||||
// Check if hooks dir exists
|
||||
if _, err := os.Stat(hooksDir); os.IsNotExist(err) {
|
||||
return "" // No git hooks directory, skip
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user