logo

stagit

STAtic GIT web view generator (in C) git clone https://hacktivis.me/git/stagit.git

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