#!/bin/sh # Place me in ".git/hooks", replacing the original file if one exists. # Stashing all non-staged changes so the lint will only run on staged changes. # Assuming the already-commited code is always linted before commiting, # this code assures that the upcoming commits will also be linted. git stash -k -u > /dev/null # This code assumes here you have some `make` commands for checking/reporting/fixing the linting of the code. # You can change these to the commands of your choice. # It is recommended to NOT lint the code automatically, but let the user decide what # to do if the code is not linted to prevent automatically-added bugs # and to allow the `git stash pop` command to always succeed. if ! make check-lint; then make report-lint echo "Can't commit changes - there are lint errors. Run 'make fix-lint' to fix issues and try again." >&2 EXIT_CODE=1 else EXIT_CODE=0 fi git stash pop > /dev/null exit $EXIT_CODE