git_infra

Git infra scripts for git.bracken.jp
git clone https://git.bracken.jp/git_infra.git
Log | Files | Refs | LICENSE

commit f770dc4319c15550653f072b0d61c88ccbdd892b
parent d7f19b93749bfc127c6ac3a7095f52bf7ae9c7b6
Author: Chris Bracken <chris@bracken.jp>
Date:   Fri, 10 May 2024 04:17:13 +0000

Add gitout post-receive hook

For now this is just a direct port of the previous stagit hook.

Diffstat:
Apost-receive.d/gitout | 77+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 77 insertions(+), 0 deletions(-)

diff --git a/post-receive.d/gitout b/post-receive.d/gitout @@ -0,0 +1,77 @@ +#!/bin/sh -e + +export LC_CTYPE="en_US.UTF-8" + +# HTML root directory into which gitout will write. +www_root="/usr/local/www/git.bracken.jp" + +# Hooks are called from the repo directory. +repo_dir=$(pwd) + +# The gitout cache file. +# This is an optimisation to avoid regenerating all pages on each push. +cachefile="${repo_dir}/.htmlcache" + +# The directory under which all repos are located. +# Repos under this directory will be added to the repo index page. +repos_root=$(dirname "$repo_dir") + +# The user-friendly name of the repository. +repo_name=$(basename "$repo_dir" '.git') + +# Detect --force pushes. +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 + echo "[gitout] Force push detected: cleaning cache" + force=1 + break + fi +done + +# If there was a --force push, delete all existing pages. The lack of a cache +# file will trigger a full rebuild below. +if [ "$force" = "1" ]; then + rm -f "$cachefile" + rm -rf "commit" "file" +fi + +# Build the pages. If $cachefile is not present, a full rebuild is performed. +if [ -e "${repo_dir}/git-daemon-export-ok" ]; then + # Change to the directory where we will output HTML pages. + repo_web_dir="${www_root}/${repo_name}" + mkdir -p "$repo_web_dir" + cd "$repo_web_dir" || exit 1 + + # Generate the index page. + # Any repo containing a gitout-no-index file will not be indexed. + echo "[gitout] Building repo index" + find "${repos_root}/." -maxdepth 1 \ + -type d \ + -name "*.git" \ + -exec test -e "{}/git-daemon-export-ok" \; \ + -exec test ! -e "{}/gitout-no-index" \; \ + -print \ + | sort -f \ + | sed -e 's/"/"\\""/g' -e 's/.*/"&"/' \ + | xargs gitout_index \ + > "${www_root}/index.html" + + # Rebuild the pages for the repo (including for unlisted repos). + echo "[gitout] Building pages" + gitout -c "$cachefile" "$repo_dir" + + # use log as index page + echo "[gitout] Linking assets" + ln -sf log.html index.html + ln -sf ../style.css style.css + ln -sf ../logo.png logo.png + ln -sf ../favicon.png favicon.png +else + echo "[gitout] Not building pages: private repo" +fi