Skip to content

Instantly share code, notes, and snippets.

@debkanchan
Created July 2, 2022 13:55
Show Gist options
  • Save debkanchan/228c21074b7d4f0bf2c3031eb7eaaa1f to your computer and use it in GitHub Desktop.
Save debkanchan/228c21074b7d4f0bf2c3031eb7eaaa1f to your computer and use it in GitHub Desktop.
Trunk git hooks setup
# 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