diff --git a/README.md b/README.md index 56b747dfb..3ab407520 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,8 @@ git commit -m "..." # Reviews happen automatically roborev tui # View reviews in interactive UI ``` +**Note**: Hook installation automatically detects your git hook manager (Husky, etc.) via `core.hooksPath`. + ## Commands | Command | Description | diff --git a/cmd/roborev/main.go b/cmd/roborev/main.go index 658e463e2..8b2bc584a 100644 --- a/cmd/roborev/main.go +++ b/cmd/roborev/main.go @@ -260,10 +260,23 @@ func initCmd() *cobra.Command { return fmt.Errorf("get hooks path: %w", err) } hookPath := filepath.Join(hooksDir, "post-commit") - hookContent := `#!/bin/sh + + // Get full path to roborev executable to avoid PATH issues in hooks + roborevPath, err := exec.LookPath("roborev") + if err != nil { + roborevPath = "roborev" // Fallback to PATH lookup + } + + // Create hook with proper quoting and fallback for moved/upgraded binaries + hookContent := fmt.Sprintf(`#!/bin/sh # RoboRev post-commit hook - auto-reviews every commit -roborev enqueue --quiet & -` +ROBOREV=%q +if [ ! -x "$ROBOREV" ]; then + ROBOREV=$(command -v roborev) || exit 0 +fi +"$ROBOREV" enqueue --quiet & +`, roborevPath) + // Ensure hooks directory exists if err := os.MkdirAll(hooksDir, 0755); err != nil { return fmt.Errorf("create hooks directory: %w", err) @@ -739,10 +752,21 @@ func installHookCmd() *cobra.Command { return fmt.Errorf("create hooks directory: %w", err) } - hookContent := `#!/bin/sh + // Get full path to roborev executable to avoid PATH issues in hooks + roborevPath, err := exec.LookPath("roborev") + if err != nil { + roborevPath = "roborev" // Fallback to PATH lookup + } + + // Create hook with proper quoting and fallback for moved/upgraded binaries + hookContent := fmt.Sprintf(`#!/bin/sh # RoboRev post-commit hook - auto-reviews every commit -roborev enqueue --quiet & -` +ROBOREV=%q +if [ ! -x "$ROBOREV" ]; then + ROBOREV=$(command -v roborev) || exit 0 +fi +"$ROBOREV" enqueue --quiet & +`, roborevPath) if err := os.WriteFile(hookPath, []byte(hookContent), 0755); err != nil { return fmt.Errorf("write hook: %w", err)