forked from joostkremers/ebib
/
pre-commit.sh
executable file
·113 lines (96 loc) · 2.6 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/bin/bash
# Purpose : pre-commit hook
# Project : ebib
# Commenced : 04-Sep-2012
# NOTES:
#
# name file : 'pre-commit.sh'
# symlink : ln --symbolic pre-commit.sh .git/hooks/pre-commit
# then : place under revision control
#
# the 'pre-commit' hook is the first of four 'git'
# hooks that are run prior to each commit
#
# this script regenerates the info file if the source file for the
# manual (ebib.text) is newer than ebib.info.
# PREAMBLE
SOURCE="manual/ebib.text" # markdown source
SOURCE_BBODY="manual/header.texi" # texinfo headers
TEXINFO="manual/ebib.texi" # texinfo output
HTML="ebib-manual.html" # html output
INFO="ebib.info" # GNU info output
SCRIPT=$(basename "$0")
E_SUCCESS=0
E_FAILURE=1
# FUNCTIONS
function confirm_file
{
local file="$1"
test -f "$file" && return 0
echo "$SCRIPT: regular file not found: $file"
let "errors++"
return 1
}
function create_texi
{
local source="$1"
echo "$SCRIPT: running pandoc to create texinfo"
pandoc --read=markdown \
--write=texinfo \
--output="$TEXINFO" \
--include-before-body="$SOURCE_BBODY" \
--standalone \
--table-of-contents \
"$1" && return 0
echo "$SCRIPT: pandoc -w texinfo failed"
let "errors++"
return 1
}
function run_makeinfo
{
local source="$1"
echo "$SCRIPT: runnig makeinfo"
makeinfo "$1" && return 0 # makeinfo puts the output file in the current dir
echo "$SCRIPT: makeinfo run failed"
let "errors++"
return 1
}
function create_html
{
local source="$1"
echo "$SCRIPT: running pandoc to create html"
pandoc --read=markdown \
--write=html \
--output="$HTML" \
--standalone \
--table-of-contents \
--css=ebib.css \
"$1" && return 0
echo "$SCRIPT: pandoc -w html failed"
let "errors++"
return 1
}
function check_exit
{
local errors="$1"
test "$errors" -eq 0 && return 0
echo "$SCRIPT: fatal: exit status $E_FAILURE"
exit $E_FAILURE
}
# ACTIVE code
errors=0
confirm_file "$SOURCE"
confirm_file "$INFO"
confirm_file "$HTML"
check_exit "$errors"
if [ "$INFO" -ot "$SOURCE" -o "$HTML" -ot "$SOURCE" ] ; then
echo "$SCRIPT: regenerating info and html files"
git stash -q --keep-index
create_texi "$SOURCE" && run_makeinfo "$TEXINFO" && git add "$INFO"
create_html "$SOURCE" && git add "$HTML"
git stash pop -q
fi
check_exit "$errors"
echo "$SCRIPT: documentation is current"
exit $E_SUCCESS
# end of file