Skip to content

Instantly share code, notes, and snippets.

@luke-biel
Last active February 17, 2020 11:14
Show Gist options
  • Save luke-biel/81c3c625e899b6aff87cabcc21904041 to your computer and use it in GitHub Desktop.
Save luke-biel/81c3c625e899b6aff87cabcc21904041 to your computer and use it in GitHub Desktop.
pre-push git hook
#!/usr/bin/env bash
# hash with 40 zeros means deleted ref
z40=0000000000000000000000000000000000000000
IFS=' '
while read -r local_ref local_sha remote_ref remote_sha
do
if [ "$local_sha" = $z40 ];
then
true # noop
else
if [ "$remote_sha" = $z40 ]
then
# New branch, examine all commits
range="$local_sha"
else
# Update to existing branch, examine new commits
range="$remote_sha..$local_sha"
fi
# Check for WIP commit
commit=$(git rev-list -n 1 --grep '^WIP' "$range")
if [ -n "$commit" ]
then
true # noop
else
cargo test --all # test cargo project if we are pushing non-WIP changes
fi
fi
done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment