example_post-receive.sh (1748B)
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.
1011
# NOTE: needs to be set for correct locale (expects UTF-8) otherwise the
12# default is LC_CTYPE="POSIX".
13export LC_CTYPE="en_US.UTF-8"
1415
name="$1"
16if test "${name}" = ""; then
17name=$(basename "$(pwd)")
18fi
1920
# config
21# paths must be absolute.
22reposdir="/home/src/src"
23dir="${reposdir}/${name}"
24htmldir="/home/www/domains/git.codemadness.org/htdocs"
25stagitdir="/"
26destdir="${htmldir}${stagitdir}"
27cachefile=".htmlcache"
28# /config
2930
if ! test -d "${dir}"; then
31echo "${dir} does not exist" >&2
32exit 1
33fi
34cd "${dir}" || exit 1
3536
# detect git push -f
37force=0
38while read -r old new ref; do
39test "${old}" = "0000000000000000000000000000000000000000" && continue
40test "${new}" = "0000000000000000000000000000000000000000" && continue
4142
hasrevs=$(git rev-list "${old}" "^${new}" | sed 1q)
43if test -n "${hasrevs}"; then
44force=1
45break
46fi
47done
4849
# strip .git suffix.
50r=$(basename "${name}")
51d=$(basename "${name}" ".git")
52printf "[%s] stagit HTML pages... " "${d}"
5354
mkdir -p "${destdir}/${d}"
55cd "${destdir}/${d}" || exit 1
5657
# remove commits and ${cachefile} on git push -f, this recreated later on.
58if test "${force}" = "1"; then
59rm -f "${cachefile}"
60rm -rf "commit"
61fi
6263
# make index.
64stagit-index "${reposdir}/"*/ > "${destdir}/index.html"
6566
# make pages.
67stagit -c "${cachefile}" -u "https://git.codemadness.nl/$d/" "${reposdir}/${r}"
6869
ln -sf log.html index.html
70ln -sf ../style.css style.css
71ln -sf ../logo.png logo.png
7273
echo "done"