Created
June 4, 2024 09:19
-
-
Save ggalmazor/a42289f3701a36d87fdd4dbe212b0731 to your computer and use it in GitHub Desktop.
Git pre-commit hook to run Rubocop on staged files
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
#!/bin/zsh | |
BRANCH_NAME=$(git branch | grep '*' | sed 's/* //') | |
if [[ $BRANCH_NAME != *"no branch"* ]] | |
then | |
FILENAMES=$(git diff --staged --name-only --diff-filter=AM | grep -e "\.rb$" -e "\.rake$") | |
if [[ -z "${FILENAMES// }" ]] | |
then | |
echo "Skipping Rubocop pre-commit hook" | |
else | |
echo "Running Rubocop pre-commit hook on:" | |
echo $FILENAMES | |
rubocop --server -A $FILENAMES | |
fi | |
else | |
echo "Skipping Rubocop pre-commit hook (rebasing)" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment