forked from martinthomson/i-d-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pre-commit.sh
executable file
·39 lines (33 loc) · 1.05 KB
/
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
38
39
#!/usr/bin/env 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
srcfiles=()
xmlfiles=()
htmlfiles=()
function cleanup() {
rm -f "${srcfiles[@]}" "${xmlfiles[@]}" "${htmlfiles[@]}"
}
function abort() {
echo "Commit refused: document build error."
echo "To commit anyway, run \"git commit --no-verify\""
cleanup
exit 1
}
trap abort ERR
trap cleanup EXIT
files=($(git status --porcelain draft-* rfc* | sed '/^[MAU]/{s/^.. //;p;};/^[RC]/{s/.* -> //;p;};d' | sort))
for f in "${files[@]}"; do
tmp="${f%.*}"-tmp$$."${f##*.}"
srcfiles+=("$tmp")
xmlfiles+=("${tmp%.*}.xml")
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=${xmlfiles[*]%.*}" EXTRA_TARGETS=false