#!/bin/shset -euif [ -t 2 ]; thenred="\e[1;31m"green="\e[1;32m"blue="\e[1;34m"grey="\e[0m"elsered=""green=""blue=""grey=""fipost_commit_hook="$(realpath -m "$0"/../git-hook-post-commit)"fail=''# cf. man 5 githooks# <local ref> SP <local object name> SP <remote ref> SP <remote object name> LFwhile read local_ref local_object_name remote_ref remote_object_name; do# never check commits already on originopts='^origin'# if we have the commit that the remote branch pointed to before, exclude it as wellopts="${opts} $(git rev-parse --not --quiet --verify "${remote_object_name}^{commit}" || true)"# check the object being pushed (if it's not null)opts="${opts} $(git rev-parse --quiet --verify "${local_object_name}^{commit}" || true)"# compute the list of commits to checkcommits="$(git rev-list ${opts})"[ -z "${commits}" ] && continueprintf "${blue}Performing pre-push checks for %s:${grey}\n" "${remote_ref}" >&2for commit in ${commits}; dosubject="$(git show --no-patch --format='%h %s' "${commit}" --)"if output="$("${post_commit_hook}" "${commit}")" && test -z "${output}"; thenprintf " - ${green}%s${grey}\n" "${subject}"elseprintf " - ${red}%s${grey}${output:+:}\n" "${subject}"printf "%s" "${output}" | sed 's/^/ /;$a\\'fail=1fidonedoneexit "${fail:-0}"