Last active
April 3, 2019 15:25
-
-
Save rohenaz/fb1865dcd23671aee95104128bb5b85d to your computer and use it in GitHub Desktop.
Pre-commit hook to automatically run standard
This file contains 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/sh | |
# save as .git/hooks/pre-commit | |
# Run standard --fix before committing | |
if git rev-parse --verify HEAD >/dev/null 2>&1 | |
then | |
against=HEAD | |
else | |
# Initial commit: diff against an empty tree object | |
against=$(git hash-object -t tree /dev/null) | |
fi | |
git diff --cached --name-only -z $against | xargs -0 standard --fix 1>&2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment