forked from martinthomson/i-d-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pre-commit.sh
executable file
·37 lines (31 loc) · 1015 Bytes
/
pre-commit.sh
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
#!/bin/bash
exec 1>&2
BRANCH=$(git symbolic-ref --short HEAD 2>/dev/null)
if [ "$BRANCH" = "gh-pages" -o "$BRANCH" = "gh-issues" -o -e .git/MERGE_HEAD ]; then
exit
fi
hash gmake 2> /dev/null && MAKE=gmake || MAKE=make
txtfiles=()
tmpfiles=()
function cleanup() {
rm -f "${tmpfiles[@]}" "${htmlfiles[@]}"
}
function abort() {
echo "Commit refused: documents don't build successfully."
echo "To commit anyway, run \"git commit --no-verify\""
cleanup
exit 1
}
trap abort ERR
trap cleanup EXIT
files=($(git status --porcelain draft-* | sed '/^[MARCU]/{s/.*draft-/draft-/;p;};d' | sort))
for f in "${files[@]}"; do
tmp="${f%.*}"-tmp$$."${f##*.}"
tmpfiles+=("$tmp")
htmlfiles+=("${tmp%.*}.html")
# This makes a copy of the staged file.
(git show :"$f" 2>/dev/null || cat "$f") \
| sed -e "s/${f%.*}-latest/${tmp%.*}-latest/g" > "$tmp"
done
[ "${#files[@]}" -eq 0 ] && exit 0
"$MAKE" "${htmlfiles[@]}" lint "drafts=${tmpfiles[*]%.*}" DISABLE_TARGETS_UPDATE=true