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:
+16
-4
@@ -459,8 +459,12 @@ func init() {
|
||||
|
||||
// hooksInstalled checks if bd git hooks are installed
|
||||
func hooksInstalled() bool {
|
||||
preCommit := filepath.Join(".git", "hooks", "pre-commit")
|
||||
postMerge := filepath.Join(".git", "hooks", "post-merge")
|
||||
gitDir, err := getGitDir()
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
preCommit := filepath.Join(gitDir, "hooks", "pre-commit")
|
||||
postMerge := filepath.Join(gitDir, "hooks", "post-merge")
|
||||
|
||||
// Check if both hooks exist
|
||||
_, err1 := os.Stat(preCommit)
|
||||
@@ -515,7 +519,11 @@ type hookInfo struct {
|
||||
|
||||
// detectExistingHooks scans for existing git hooks
|
||||
func detectExistingHooks() []hookInfo {
|
||||
hooksDir := filepath.Join(".git", "hooks")
|
||||
gitDir, err := getGitDir()
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
hooksDir := filepath.Join(gitDir, "hooks")
|
||||
hooks := []hookInfo{
|
||||
{name: "pre-commit", path: filepath.Join(hooksDir, "pre-commit")},
|
||||
{name: "post-merge", path: filepath.Join(hooksDir, "post-merge")},
|
||||
@@ -569,7 +577,11 @@ func promptHookAction(existingHooks []hookInfo) string {
|
||||
|
||||
// installGitHooks installs git hooks inline (no external dependencies)
|
||||
func installGitHooks() error {
|
||||
hooksDir := filepath.Join(".git", "hooks")
|
||||
gitDir, err := getGitDir()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
hooksDir := filepath.Join(gitDir, "hooks")
|
||||
|
||||
// Ensure hooks directory exists
|
||||
if err := os.MkdirAll(hooksDir, 0750); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user