#!/bin/sh

# this is literally the simplest gitweb update possible.  You are free to add
# whatever you want and contribute it back, as long as it is upward
# compatible.

# ----------------------------------------------------------------------
# delete the 'description' file that 'git init' created if this is run from
# the post-create trigger.  However, note that POST_CREATE is also called from
# perms (since POST_CREATE doubles as eqvt of POST_COMPILE to propagate ad hoc
# permissions changes for wild repos) and then you should not delete it.
[ "$1" = "POST_CREATE" ] && [ "$4" != "perms" ] && rm -f $GL_REPO_BASE/$2.git/description 2>/dev/null

# ----------------------------------------------------------------------
# skip if arg-1 is POST_CREATE and no arg-3 (user name) exists; this means
# it's been triggered by a *normal* (not "wild") repo creation, which in turn
# means a POST_COMPILE should be following so there's no need to waste time
# running this once for each new repo
[ "$1" = "POST_CREATE" ] && [ -z "$3" ] && exit 0;

plf=`gitolite query-rc GITWEB_PROJECTS_LIST`
[ -z "$plf" ] && plf=$HOME/projects.list
# since mktemp does not honor umask, we just use it to generate a temp filename
tmpfile=`mktemp -u $plf.tmp_XXXXXXXX`
(
    gitolite list-phy-repos | gitolite access % gitweb R any | grep -v DENIED
    gitolite list-phy-repos | gitolite git-config -r % gitweb\\.
) |
    cut -f1 | sort -u | sed -e 's/$/.git/' > $tmpfile
mv $tmpfile $plf
