Skip to content

fix(hook): run prepare-commit-msg without node in PATH - #600

Open
SajjadPSavoji wants to merge 1 commit into
di-sukharev:masterfrom
SajjadPSavoji:fix-422-bug-oco-hook-set
Open

SajjadPSavoji wants to merge 1 commit into
di-sukharev:masterfrom
SajjadPSavoji:fix-422-bug-oco-hook-set

Conversation

@SajjadPSavoji

Copy link
Copy Markdown

oco hook set symlinked the CLI as the hook, which relies on #!/usr/bin/env node. Git GUI clients like the vscode source control panel often start hooks without node in PATH, so commits failed with env: node: No such file or directory.

Now set writes a small /bin/sh launcher that runs the CLI with the absolute, shell-quoted process.execPath and CLI path. It also exports OCO_GIT_HOOK=1 so isHookCalled still detects hook mode, since argv[1] is now cli.cjs. Old symlinks and outdated launchers get replaced, running set again says already set, and a foreign or dangling hook is refused on set and left alone on unset. The README now says to rerun oco hook set after switching or removing a node version.

Thanks @di-sukharev for the approach.

Tests: the new unit test in test/unit/githook.test.ts runs the launcher with a bogus PATH and paths with spaces and quotes. In test/e2e/cliBehavior.test.ts I added tests for replacing a legacy symlink and an outdated launcher, keeping a foreign or dangling hook, and a real git commit after hook set with PATH=/usr/bin:/bin. I ran the unit tests in githook.test.ts and setup.test.ts, plus biome check and tsc --noEmit. I did not run the full suite, so the e2e tests were not run here.

Fixes #422

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.

[Bug]: oco hook set is blocking vscode integrated source control

1 participant