stagit-scripts

Static git repository setup scripts
git clone https://www.brianlane.com/git/stagit-scripts
Log | Files | Refs | README

post-receive (1846B)


      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 BASEURL="https://www.yourhost.com/git"
     23 RSYNC_DEST="yourhost.com:public_html/git/"
     24 reposdir="$HOME/stagit-repos"
     25 
     26 dir="${reposdir}/${name}"
     27 htmldir="${reposdir}"
     28 stagitdir="/"
     29 destdir="${htmldir}${stagitdir}"
     30 cachefile=".htmlcache"
     31 # /config
     32 
     33 if ! test -d "${dir}"; then
     34 	echo "${dir} does not exist" >&2
     35 	exit 1
     36 fi
     37 cd "${dir}" || exit 1
     38 
     39 # detect git push -f
     40 force=0
     41 while read -r old new ref; do
     42 	test "${old}" = "0000000000000000000000000000000000000000" && continue
     43 	test "${new}" = "0000000000000000000000000000000000000000" && continue
     44 
     45 	hasrevs=$(git rev-list "${old}" "^${new}" | sed 1q)
     46 	if test -n "${hasrevs}"; then
     47 		force=1
     48 		break
     49 	fi
     50 done
     51 
     52 printf "[%s] stagit HTML pages... " "${name}"
     53 
     54 mkdir -p "${destdir}/${name}"
     55 cd "${destdir}/${name}" || exit 1
     56 
     57 # remove commits and ${cachefile} on git push -f, this recreated later on.
     58 if test "${force}" = "1"; then
     59 	rm -f "${cachefile}"
     60 	rm -rf "commit"
     61 fi
     62 
     63 # make index.
     64 stagit-index "${reposdir}/"*/ > "${destdir}/index.html"
     65 
     66 # Create the URL for clone
     67 echo "${BASEURL}/${name}" > url
     68 git update-server-info
     69 
     70 # make pages.
     71 stagit -c "${cachefile}" "${reposdir}/${name}"
     72 
     73 ln -sf log.html index.html
     74 ln -sf ../style.css style.css
     75 ln -sf ../logo.png logo.png
     76 
     77 # Update the server
     78 rsync -a "${destdir}/" "${RSYNC_DEST}"
     79 
     80 echo "done"