commit ca5f6f2c62bd43443b813f796290a24030576852
Author: kst
Date: 2020-07-17 23:41Z

add example post-receive hook

Diffstat:
Astagit-post-receive | 68++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 68 insertions(+), 0 deletions(-)

diff --git a/stagit-post-receive b/stagit-post-receive @@ -0,0 +1,68 @@ +#!/bin/sh +# post-receive hooks for updating stagit web pages, +# modified from the example in original stagit repo + +#---------------+----------+-----------------# +# | config | # +# +----------+ # + +# root directory of stagit web pages +STAGIT_WEB_ROOT="$HOME/public_html/git" + +# # +# # +#--------------------------------------------# + +export LC_CTYPE="en_US.UTF-8" + +web_root=${STAGIT_WEB_ROOT:-$HOME/public_html/git} + +# hooks are called from the repo directory +repo_dir=$(pwd) +repos_root=$(dirname "$repo_dir") +repo_name=$(basename "$repo_dir" '.git') +cachefile="${repo_dir}/.htmlcache" + +# step 1: detect git push -f +cd "$repo_dir" || exit 1 +force=0 +while read -r old new _; do + [ "$old" = "0000000000000000000000000000000000000000" ] && continue + [ "$new" = "0000000000000000000000000000000000000000" ] && continue + + hasrevs=$(git rev-list "$old" "^$new" | sed 1q) + if [ -n "$hasrevs" ]; then + printf "[%s] force push detected, will clean up cache\n" "$repo_name" + force=1 + break + fi +done + +printf "[%s] stagit HTML pages... " "$repo_name" + +# step 2: generate stagit pages +repo_web_dir="${web_root}/${repo_name}" +mkdir -p "$repo_web_dir" +cd "$repo_web_dir" || exit 1 + +# remove commits and $cachefile on git push -f +# this is recreated later on +if [ "$force" = "1" ]; then + rm -f "$cachefile" + rm -rf "commit" "file" +fi + +# make index for public repos +find "${repos_root}/." ! -name . -prune \ + -type d -name "*.git" \ + -exec test ! -e "{}/stagit-no-index" \; \ + -print | \ + sort -f | xargs stagit-index > "${web_root}/index.html" + +# make pages. +stagit -c "$cachefile" "$repo_dir" + +# use log as index page +ln -sf log.html index.html + +echo "done!"