Created
September 11, 2020 19:57
-
-
Save beaucollins/e18b7aeb8f12679875b25304725e9e43 to your computer and use it in GitHub Desktop.
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/sh | |
| remote="$1" | |
| url="$2" | |
| z40=0000000000000000000000000000000000000000 | |
| while read local_ref local_sha remote_ref remote_sha | |
| do | |
| if [ "$local_sha" = $z40 ] | |
| then | |
| # Handle delete | |
| : | |
| else | |
| if [ "$remote_sha" = $z40 ] | |
| then | |
| # New branch, examine all commits | |
| range="$(git symbolic-ref refs/remotes/$remote/HEAD)..$local_sha" | |
| else | |
| # Update to existing branch, examine new commits | |
| range="$remote_sha..$local_sha" | |
| fi | |
| files=$(git diff --diff-filter=ACMR --name-only "$range") | |
| if [ -z $files ]; then | |
| echo "No files to check." | |
| exit | |
| fi; | |
| echo "Checking prettier for $files" | |
| npx prettier --check $files | |
| fi | |
| done | |
| exit 0 |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Put it in
./git/hooks/pre-pushand thenchmod +xit.