-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit-pre-recieve-hook
executable file
·51 lines (39 loc) · 1.4 KB
/
git-pre-recieve-hook
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/bash
cleanup() {
[ -z "${UKECHORD_PYDIR+x}" ] || rm -Rf "$UKECHORDS_PYDIR"
[ -z "${SRC_DIR+x}" ] || rm -Rf "$SRC_DIR"
}
fail() {
echo "$*"
cleanup
exit 1
}
trap "cleanup" SIGINT SIGTERM ERR
set -Eeuo pipefail
if [ "$#" -gt 0 ] && [ "$1" = "-d" ]; then
echo "Working in diagnostic mode instead of as git hook"
if [ -n "$(git status --untracked-files=no --porcelain)" ]; then
fail "Can't run in diagnostic mode in dirty git state"
fi
echo 0000000000000000000000000000000000000000 HEAD null | "$0"
exit
fi
while read -r OLDREV NEWREV REFNAME; do
echo "Handling request to move $REFNAME from $OLDREV -> $NEWREV"
if [ "$OLDREV" != "0000000000000000000000000000000000000000" ]; then
BADCOMMITS="$(git log --pretty=%h --grep "fixup!" --grep "squash!" "$OLDREV..$NEWREV")"
if [ -n "$BADCOMMITS" ]; then
fail "{$(echo $BADCOMMITS | sed 's/ /, /g')} are uncaught fixup/squash commits."
fi
fi
export UKECHORDS_PYDIR="$(mktemp -d -p /tmp tmp_ukechords_pydir_XXXX)"
export SRC_DIR="$(mktemp -d -p /tmp tmp_ukechords_src_XXXX)"
git archive "$NEWREV" | tar -x -C "$SRC_DIR"
python -m venv "$UKECHORDS_PYDIR"
cd "$SRC_DIR"
(. "$UKECHORDS_PYDIR/bin/activate"; pip install --upgrade pip flit; flit install)
if ! ./run_ci.sh; then
fail "CI checks failed, rejecting commit"
fi
cleanup
done