Created
July 2, 2022 13:55
-
-
Save debkanchan/228c21074b7d4f0bf2c3031eb7eaaa1f to your computer and use it in GitHub Desktop.
Trunk git hooks setup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# We will use .githooks as hooks path but you can use your own | |
mkdir .githooks | |
# Add the pre-commit formatting hook | |
cat >>.githooks/pre-commit <<EOF | |
trunk fmt | |
EOF | |
# Add pre push linting hook | |
cat >>.githooks/pre-push <<EOF | |
# This is required somewhere in your script to accept user input from the keyboard. | |
exec < /dev/tty | |
trunk check --trigger=git-push | |
EOF | |
# IMPORTANT!: if you're NOT using .githooks as your hooks path then change .githooks to your hooks path git config line or comment it out | |
cat >>.githooks/setup.sh <<EOF | |
#!/bin/bash | |
git config core.hooksPath .githooks | |
chmod +x .githooks/pre-commit | |
chmod +x .githooks/pre-push | |
EOF | |
# Run setup.sh to finally activate the hooks | |
chmod +x .githooks/setup.sh | |
.githooks/setup.sh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment