Skip to content

Instantly share code, notes, and snippets.

@beaucollins
Created September 11, 2020 19:57
Show Gist options
  • Select an option

  • Save beaucollins/e18b7aeb8f12679875b25304725e9e43 to your computer and use it in GitHub Desktop.

Select an option

Save beaucollins/e18b7aeb8f12679875b25304725e9e43 to your computer and use it in GitHub Desktop.
#!/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
@beaucollins

Copy link
Copy Markdown
Author

Put it in ./git/hooks/pre-push and then chmod +x it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment