From bf331373bcfecae8a542f15ca2398c67bd32dc7a Mon Sep 17 00:00:00 2001 From: Tenzin Wangdhen Date: Thu, 8 Jan 2026 16:31:30 -0800 Subject: [PATCH 1/5] feat: Use full path to roborev in git hooks Resolve roborev executable path at hook installation time using exec.LookPath() to avoid PATH issues in git hook environments. Benefits: - Fixes hooks in environments where PATH is not fully set - Works with any hook manager (Husky, lefthook, etc.) - Upstream git.GetHooksPath() already handles hook manager detection Changes: - Update initCmd() to resolve full roborev path - Update installHookCmd() to use full path - Add brief README note about automatic detection Co-Authored-By: Claude Sonnet 4.5 --- README.md | 2 ++ cmd/roborev/main.go | 28 +++++++++++++++++++++------- 2 files changed, 23 insertions(+), 7 deletions(-) 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..62feca4dc 100644 --- a/cmd/roborev/main.go +++ b/cmd/roborev/main.go @@ -254,16 +254,24 @@ func initCmd() *cobra.Command { } } - // 4. Install post-commit hook + // 4. Install post-commit hook hooksDir, err := git.GetHooksPath(root) if err != nil { 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 + } + + hookContent := fmt.Sprintf(`#!/bin/sh # RoboRev post-commit hook - auto-reviews every commit -roborev enqueue --quiet & -` +%s 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 +747,16 @@ 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 + } + + hookContent := fmt.Sprintf(`#!/bin/sh # RoboRev post-commit hook - auto-reviews every commit -roborev enqueue --quiet & -` +%s enqueue --quiet & +`, roborevPath) if err := os.WriteFile(hookPath, []byte(hookContent), 0755); err != nil { return fmt.Errorf("write hook: %w", err) From 8dc28e3cf95e637895e1bd58425887267c1497f7 Mon Sep 17 00:00:00 2001 From: Tenzin Wangdhen Date: Thu, 8 Jan 2026 16:34:54 -0800 Subject: [PATCH 2/5] test: Trigger roborev with codex agent Testing roborev auto-review with real agent. Co-Authored-By: Claude Sonnet 4.5 From 88584e651c03f5dd8f9b1e402e6005bce84f32d9 Mon Sep 17 00:00:00 2001 From: Tenzin Wangdhen Date: Thu, 8 Jan 2026 16:36:13 -0800 Subject: [PATCH 3/5] fix: Correct indentation on comment Remove extra tab added by mistake on line 257. Co-Authored-By: Claude Sonnet 4.5 --- cmd/roborev/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/roborev/main.go b/cmd/roborev/main.go index 62feca4dc..4b74beb27 100644 --- a/cmd/roborev/main.go +++ b/cmd/roborev/main.go @@ -254,7 +254,7 @@ func initCmd() *cobra.Command { } } - // 4. Install post-commit hook + // 4. Install post-commit hook hooksDir, err := git.GetHooksPath(root) if err != nil { return fmt.Errorf("get hooks path: %w", err) From 4849d84ec3dc8dcc4c7f7c44d14cd1604c9f48d8 Mon Sep 17 00:00:00 2001 From: Tenzin Wangdhen Date: Thu, 8 Jan 2026 16:45:47 -0800 Subject: [PATCH 4/5] test: Verify improved hook with quoting and fallback Co-Authored-By: Claude Sonnet 4.5 From 85320040b89de7c62a38f392131b7f35cf2d95aa Mon Sep 17 00:00:00 2001 From: Tenzin Wangdhen Date: Thu, 8 Jan 2026 16:46:02 -0800 Subject: [PATCH 5/5] fix: Add shell quoting and fallback to hook generation Address PR feedback: 1. **Shell escaping (Medium)**: Use %q format specifier to properly quote the roborev path, handling spaces and special characters. 2. **Stale path fallback (Low)**: Add runtime check that falls back to 'command -v roborev' if the hardcoded path is moved/upgraded. Generated hook now: - Sets ROBOREV variable with quoted path - Checks if path exists and is executable - Falls back to PATH lookup if not - Properly quotes $ROBOREV when executing Example generated hook: ```bash #!/bin/sh ROBOREV="/path/to/roborev" if [ ! -x "$ROBOREV" ]; then ROBOREV=$(command -v roborev) || exit 0 fi "$ROBOREV" enqueue --quiet & ``` Co-Authored-By: Claude Sonnet 4.5 --- cmd/roborev/main.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/cmd/roborev/main.go b/cmd/roborev/main.go index 4b74beb27..8b2bc584a 100644 --- a/cmd/roborev/main.go +++ b/cmd/roborev/main.go @@ -267,9 +267,14 @@ func initCmd() *cobra.Command { 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 -%s enqueue --quiet & +ROBOREV=%q +if [ ! -x "$ROBOREV" ]; then + ROBOREV=$(command -v roborev) || exit 0 +fi +"$ROBOREV" enqueue --quiet & `, roborevPath) // Ensure hooks directory exists @@ -753,9 +758,14 @@ func installHookCmd() *cobra.Command { 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 -%s 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 {