-
Notifications
You must be signed in to change notification settings - Fork 843
Jetpack CLI: Add Docker-based git hooks support #46462
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot wasn't able to review any files in this pull request.
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 2 out of 4 changed files in this pull request and generated no new comments.
- Reformat chalk.yellow call to single line to match code style - Update changelog for 1.1.0-beta.0 release
Follow bash best practices by using [[ ]] builtin syntax for the TTY check conditional, consistent with bash scripting conventions.
The post-checkout hook was failing when checking out with no previous ref (e.g., fresh clone or initial checkout) because it tried to run git diff-tree with an empty argument. Added a check to skip the hook if the previous ref is empty or is the null SHA (all zeros), which git uses to indicate no previous ref exists.
|
What do you think of this approach? My intent is people who are already setup can continue to use I tested it by deleting pnpm off my local system and able to switch back. I feel like this might be the way to do it without any of the previous ideas I had (wrapping |
anomiex
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks reasonable, except for one thing flagged inline.
What stops any later pnpm install from re-initializing husky (and re-setting core.hookspath) though?
Nothing at this point. Intentional to not force a change to using |
|
I meant even a |
- Revert package.json version from 1.1.0-beta.0 to 1.0.2 - Remove premature changelog entry from CHANGELOG.md - Add runtime detection to display alpha version when running from source - Add proper changelog entry files for changelogger
Address review feedback to avoid repeating hook command data. Now both initHooks and runGitHook use getHookCommand() to read the actual commands from .husky/ files, staying in sync with husky.
|
Good point.
So the container's git config can point to Still need to test some edge cases though—particularly when pre-commit catches a fixable linting issue, auto-fixes and commits it, then signals to continue with the original operation. Adding those test cases now. |
Hmm, I think my test of all this by just deleting pnpm is insufficient... I'll keep working on it. Thanks. |
|
Looking at the docs ( https://typicode.github.io/husky/how-to.html#ci-server-and-docker ), there are a few options I'm going to explore. |
Instead of extracting commands from .husky files, run them directly via `sh .husky/<hookname>`. This is more maintainable and handles all the shell logic (like TTY handling in pre-push) properly.
Set HUSKY=0 to prevent husky from modifying the shared .git/config when pnpm install runs in the container. Since .git is bind-mounted, husky's prepare script would otherwise set core.hooksPath and bypass the jp hooks installed in .git/hooks/.
|
Good points on both counts:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 4 out of 6 changed files in this pull request and generated no new comments.
- Remove shell: true from spawnSync to preserve argument quoting (fixes changelog entries with spaces being split) - Only set CI=true when no TTY available, allowing interactive prompts like changelog creation during git push
|
I tested the various git hooks that auto-commit, prompt the interactive changelog, etc and made a few changes. I believe this is ready for review and merge. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 4 out of 6 changed files in this pull request and generated 1 comment.
- Read git hooks dynamically from .husky/ directory instead of hardcoding - Add existence check in generated hooks for graceful degradation - Minor style improvement for TTY check condition
TTY detection is already handled by the monorepo script, which reconnects to /dev/tty when available.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 4 out of 6 changed files in this pull request and generated no new comments.
Proposed changes:
jp init-hookscommand to install Docker-aware git hooksjp git-hook <hook-name>command to run git hooks inside Docker containerjp init-hooksduringjp initfor new installationscore.hooksPathif configured (e.g., from husky) to ensure jp hooks are usedmonoreposcript to avoid "input device is not a TTY" errors when running in non-interactive contextsCI=trueenvironment variable when running git hooks to prevent pnpm from requiring TTYJETPACK_MONOREPO_ENV=1to Docker container to allow hooks to detect when running inside Docker.husky/files to stay in sync with husky configurationOther information:
Jetpack product discussion
N/A - Internal developer tooling improvement
Does this pull request change what data or activity we track or use?
No
The following edge cases need manual testing:
Testing instructions:
Prerequisites:
git checkout update/jetpack-cli-git-hookscd projects/js-packages/jetpack-cli && npm install && npm linkcd ../../..Test 1: Install jp hooks
jp init-hooksls -la .git/hooks/shows executable hook files with recent timestampsTest 2: Test hooks run in Docker
echo "# test" >> README.mdgit add README.mdgit commit -m "Test hooks"git reset HEAD~1 && git restore README.mdTest 3: Verify normal jp commands remain interactive
jp installTest 4: Verify hooks work without host pnpm install
pnpm install