Skip to content

feat: Add Husky git hook manager support#11

Merged
wesm merged 5 commits intoroborev-dev:mainfrom
sinzin91:fix/husky-support
Jan 9, 2026
Merged

feat: Add Husky git hook manager support#11
wesm merged 5 commits intoroborev-dev:mainfrom
sinzin91:fix/husky-support

Conversation

@sinzin91
Copy link
Copy Markdown
Contributor

@sinzin91 sinzin91 commented Jan 9, 2026

Summary

Fixes roborev hooks not working in repositories that use Husky or other git hook managers. The issue occurred because hooks couldn't find the roborev executable in their minimal PATH environment.

Problem

When testing roborev on a repository using Husky, automatic reviews never triggered. Two issues were discovered:

  1. Husky compatibility: Upstream's git.GetHooksPath() already handles this correctly by respecting core.hooksPath, but hooks were still failing
  2. PATH issue: Git hooks run with a minimal environment where roborev (installed via go install in $GOPATH/bin) wasn't in PATH, causing silent failures

Solution

Use exec.LookPath("roborev") at hook installation time to resolve and embed the full executable path in the hook:

# Before (fails if roborev not in PATH)
roborev enqueue --quiet &

# After (always works)
/Users/user/.local/bin/roborev enqueue --quiet &

Why this works for Husky: The upstream git.GetHooksPath() already handles Husky detection automatically by reading core.hooksPath git config. Our change just ensures the hook content works once it's installed in the right location.

Testing

Tested successfully on repo that uses Husky:

  • ✅ Hook correctly installed to .husky/post-commit (via existing git.GetHooksPath())
  • ✅ Hook uses full path
  • ✅ Auto-review triggered on commit (Job 7 completed successfully)

Also tested on repo with no Husky:

  • ✅ Hook installed to .git/hooks/post-commit
  • ✅ Auto-reviews working (Jobs 5 & 6 completed)

Changed files

  • cmd/roborev/main.go - Add exec.LookPath() resolution in initCmd() and installHookCmd()
  • README.md - Add note about automatic hook manager detection

Breaking Changes

None. Existing installations continue to work. New installations get more reliable hooks that work with Husky and similar tools.

🤖 Generated with Claude Code

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 <[email protected]>
sinzin91 and others added 4 commits January 8, 2026 16:34
Testing roborev auto-review with real agent.

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Remove extra tab added by mistake on line 257.

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
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 <[email protected]>
@wesm wesm merged commit 7daab0f into roborev-dev:main Jan 9, 2026
2 checks passed
andyxhadji pushed a commit to andyxhadji/roborev that referenced this pull request Jan 9, 2026
## Summary

Fixes roborev hooks not working in repositories that use Husky or other
git hook managers. The issue occurred because hooks couldn't find the
`roborev` executable in their minimal PATH environment.

## Problem

When testing roborev on a repository using Husky, automatic reviews
never triggered. Two issues were discovered:

1. **Husky compatibility**: Upstream's `git.GetHooksPath()` already
handles this correctly by respecting `core.hooksPath`, but hooks were
still failing
2. **PATH issue**: Git hooks run with a minimal environment where
`roborev` (installed via `go install` in `$GOPATH/bin`) wasn't in PATH,
causing silent failures

## Solution

Use `exec.LookPath("roborev")` at hook installation time to resolve and
embed the full executable path in the hook:

```bash
# Before (fails if roborev not in PATH)
roborev enqueue --quiet &

# After (always works)
/Users/user/.local/bin/roborev enqueue --quiet &
```

**Why this works for Husky**: The upstream `git.GetHooksPath()` already
handles Husky detection automatically by reading `core.hooksPath` git
config. Our change just ensures the hook content works once it's
installed in the right location.

## Testing

Tested successfully on repo that uses Husky:
- ✅ Hook correctly installed to `.husky/post-commit` (via existing
`git.GetHooksPath()`)
- ✅ Hook uses full path
- ✅ Auto-review triggered on commit (Job 7 completed successfully)

Also tested on repo with no Husky:
- ✅ Hook installed to `.git/hooks/post-commit`
- ✅ Auto-reviews working (Jobs 5 & 6 completed)

## Changed files

- `cmd/roborev/main.go` - Add `exec.LookPath()` resolution in
`initCmd()` and `installHookCmd()`
- `README.md` - Add note about automatic hook manager detection

## Breaking Changes

None. Existing installations continue to work. New installations get
more reliable hooks that work with Husky and similar tools.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Sonnet 4.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants