fix(hooks): prevent stdin drain from skipping subsequent hooks#165
fix(hooks): prevent stdin drain from skipping subsequent hooks#165acevif wants to merge 4 commits intocoderabbitai:mainfrom
Conversation
Add </dev/null to hook subshell to prevent commands that read stdin (e.g. cat, read) from consuming the heredoc that feeds hook lines, which caused all subsequent hooks to be silently skipped. Fixes coderabbitai#164
Verify that a hook running `cat` (which reads stdin) does not prevent subsequent hooks from executing.
Add </dev/null to eval in run_hooks_export so hooks that read stdin (e.g. cat, read) do not consume the heredoc feeding hook lines, which caused subsequent postCd hooks to be silently skipped. Also adds a regression test for the postCd case.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
WalkthroughFixed a bug where hook execution would stop prematurely if any hook read from stdin by redirecting stdin from Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
Fixes #164
All hook phases (
postCreate,preRemove,postRemove,postCd) suffered from the same bug: a hook that reads from stdin (e.g.cat,read) drains the heredoc that feeds hook lines, causing all subsequent hooks to be silently skipped.run_hooks: add</dev/nullto the hook subshell(...) </dev/nullrun_hooks_export: add</dev/nullto theevalcall (eval "$hook" </dev/null)Both fixes prevent the hook from inheriting the heredoc as stdin while preserving all existing behavior (env var exports, exit code propagation, subshell isolation).
Test plan
postCreate— verifiescatbetween two hooks does not skip the thirdpreRemoveandpostRemovepostCd(viarun_hooks_export)bats tests/— 368 → 372 tests, all green)Summary by CodeRabbit