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:
@@ -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")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user