Skip to content

Instantly share code, notes, and snippets.

@nielsmh
Created April 27, 2018 12:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nielsmh/08ae4217f3e0510d38be89357e941de8 to your computer and use it in GitHub Desktop.
Save nielsmh/08ae4217f3e0510d38be89357e941de8 to your computer and use it in GitHub Desktop.
#!/bin/sh
# Check a series of commits
# Example:
# check-commits-client HEAD^..HEAD
set -e
# --- Safety check
if [ -z "${GIT_DIR}" ]; then
echo "Don't run this script from the command line." >&2
echo " (if you want, you could supply GIT_DIR then run" >&2
echo " $0 <oldrev>..<newrev>)" >&2
exit 1
fi
HOOKS_DIR=${HOOKS_DIR:-${GIT_DIR}/hooks}
tmp_msg_file=$(mktemp)
tmp_diff_file=$(mktemp)
failure=0
finish() {
rm -f ${tmp_msg_file} ${tmp_diff_file}
}
trap finish EXIT
hashes=$(git rev-list "$1")
for h in ${hashes}
do
echo Checking $h... >&2
LC_ALL=C git diff ${h}^..${h} > ${tmp_diff_file}
${HOOKS_DIR}/check-diff.py ${tmp_diff_file} || failure=1
git cat-file commit ${h} | sed '1,/^$/d' > ${tmp_msg_file}
${HOOKS_DIR}/check-message.py ${tmp_msg_file} server || failure=1
done
return $failure
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment