]> git.armaanb.net Git - stagit.git/blob - example_post-receive.sh
ignore object 0000000000000000000000000000000000000000
[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 name="$1"
12 if test "${name}" = ""; then
13         name=$(basename $(pwd))
14 fi
15
16 # config
17 # paths must be absolute.
18 reposdir="/home/src/src"
19 dir="${reposdir}/${name}"
20 htmldir="/home/www/domains/git.codemadness.org/htdocs"
21 stagitdir="/"
22 destdir="${htmldir}${stagitdir}"
23 cachefile=".htmlcache"
24 # /config
25
26 if ! test -d "${dir}"; then
27         echo "${dir} does not exist" >&2
28         exit 1
29 fi
30 cd "${dir}" || exit 1
31
32 # detect git push -f
33 force=0
34 while read -r old new ref; do
35         test "${old}" = "0000000000000000000000000000000000000000" && continue
36
37         hasrevs=$(git rev-list "${old}" "^${new}" | sed 1q)
38         if test -n "${hasrevs}"; then
39                 force=1
40                 break
41         fi
42 done
43
44 # strip .git suffix.
45 r=$(basename "${name}")
46 d=$(basename "${name}" ".git")
47 printf "[%s] stagit HTML pages... " "${d}"
48
49 mkdir -p "${destdir}/${d}"
50 cd "${destdir}/${d}" || exit 1
51
52 # remove commits and ${cachefile} on git push -f, this recreated later on.
53 if test "${force}" = "1"; then
54         rm -f "${cachefile}"
55         rm -rf "commit"
56 fi
57
58 # make index.
59 stagit-index "${reposdir}/"*/ > "${destdir}/index.html"
60
61 # make pages.
62 stagit -c "${cachefile}" "${reposdir}/${r}"
63
64 ln -sf log.html index.html
65 ln -sf ../style.css style.css
66 ln -sf ../logo.png logo.png
67
68 echo "done"