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>
42 lines
1.0 KiB
Go
42 lines
1.0 KiB
Go
package fix
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"os/exec"
|
|
)
|
|
|
|
// GitHooks fixes missing or broken git hooks by calling bd hooks install
|
|
func GitHooks(path string) error {
|
|
// Validate workspace
|
|
if err := validateBeadsWorkspace(path); err != nil {
|
|
return 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")
|
|
}
|
|
|
|
// Get bd binary path
|
|
bdBinary, err := getBdBinary()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// Run bd hooks install
|
|
cmd := exec.Command(bdBinary, "hooks", "install") // #nosec G204 -- bdBinary from validated executable path
|
|
cmd.Dir = path // Set working directory without changing process dir
|
|
cmd.Stdout = os.Stdout
|
|
cmd.Stderr = os.Stderr
|
|
|
|
if err := cmd.Run(); err != nil {
|
|
return fmt.Errorf("failed to install hooks: %w", err)
|
|
}
|
|
|
|
return nil
|
|
}
|