-
Notifications
You must be signed in to change notification settings - Fork 37
/
pre-commit.sh
executable file
·117 lines (99 loc) · 2.91 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
114
115
116
117
#!/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
TEXINFO_BBODY="manual/before-body.texi" # texinfo headers
TEXINFO="manual/ebib.texi" # texinfo output
INFO="ebib.info" # GNU info output
HTML_HEADERS="manual/header-include.html" # HTML header includes
HTML="docs/ebib-manual.html" # HTML output
CSS="styles/manual.css" # CSS file
SCRIPT=$(basename "$0")
E_SUCCESS=0
E_FAILURE=1
unset GIT_LITERAL_PATHSPECS # See Magit FAQ A.2.10 and https://github.com/magit/magit/discussions/4654
# 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+gfm_auto_identifiers \
--write=texinfo \
--output="$TEXINFO" \
--include-before-body="$TEXINFO_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 \
--standalone \
--table-of-contents \
--css="$CSS" \
--include-in-header="$HTML_HEADERS" \
--output="$HTML" \
"$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"
check_exit "$errors"
if [ "$(git status --porcelain manual/ebib.text)" == 'M manual/ebib.text' ] ; then
echo "$SCRIPT: regenerating manual 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