]> git.armaanb.net Git - stagit.git/blob - example_post-receive.sh
post-receive hook: force UTF-8 locale
[stagit.git] / example_post-receive.sh
1 #!/bin/sh
2 # generic git post-receive hook.
3 # change the config options below and call this script in your post-receive
4 # hook or symlink it.
5 #
6 # usage: $0 [name]
7 #
8 # if name is not set the basename of the current directory is used,
9 # this is the directory of the repo when called from the post-receive script.
10
11 # NOTE: needs to be set for correct locale (expects UTF-8) otherwise the
12 #       default is LC_CTYPE="POSIX".
13 export LC_CTYPE="en_US.UTF-8"
14
15 name="$1"
16 if test "${name}" = ""; then
17         name=$(basename $(pwd))
18 fi
19
20 # config
21 # paths must be absolute.
22 reposdir="/home/src/src"
23 dir="${reposdir}/${name}"
24 htmldir="/home/www/domains/git.codemadness.org/htdocs"
25 stagitdir="/"
26 destdir="${htmldir}${stagitdir}"
27 cachefile=".htmlcache"
28 # /config
29
30 if ! test -d "${dir}"; then
31         echo "${dir} does not exist" >&2
32         exit 1
33 fi
34 cd "${dir}" || exit 1
35
36 # detect git push -f
37 force=0
38 while read -r old new ref; do
39         test "${old}" = "0000000000000000000000000000000000000000" && continue
40
41         hasrevs=$(git rev-list "${old}" "^${new}" | sed 1q)
42         if test -n "${hasrevs}"; then
43                 force=1
44                 break
45         fi
46 done
47
48 # strip .git suffix.
49 r=$(basename "${name}")
50 d=$(basename "${name}" ".git")
51 printf "[%s] stagit HTML pages... " "${d}"
52
53 mkdir -p "${destdir}/${d}"
54 cd "${destdir}/${d}" || exit 1
55
56 # remove commits and ${cachefile} on git push -f, this recreated later on.
57 if test "${force}" = "1"; then
58         rm -f "${cachefile}"
59         rm -rf "commit"
60 fi
61
62 # make index.
63 stagit-index "${reposdir}/"*/ > "${destdir}/index.html"
64
65 # make pages.
66 stagit -c "${cachefile}" "${reposdir}/${r}"
67
68 ln -sf log.html index.html
69 ln -sf ../style.css style.css
70 ln -sf ../logo.png logo.png
71
72 echo "done"