strftime.c: implement %N format specifier with extra semantics
[girocco/readme.git] / hooks / post-receive
blob4a04c6119543945a296edfd0e8ef26118ed1fb18
1 #!/bin/sh
3 # Keep lastactivity and personal mob (if enabled) up-to-date
4 # We use receive.updateserverinfo=true so no need to run update-server-info
5 # Send notification through the taskd socket if it exists and not personal mob push
7 # Beware, we MAY be running in a chroot!
9 set -e
11 # Make sure the current directory is where we expect to be
12 [ "${GIT_DIR+set}" != "set" ] || cd "${GIT_DIR:-.}" || exit 1
13 case "${PWD%/*}" in */worktrees)
14 # Gah!
16 # But it COULD just be a coincidence...
17 [ -s commondir ] && [ -s HEAD ] &&
18 _cmndir= && read -r _cmndir <commondir 2>/dev/null &&
19 [ -n "$_cmndir" ] && [ -d "$_cmndir" ]
20 then
21 # ...it is not, fix it!
22 cd "$_cmndir" || exit 1
24 esac
25 [ "${GIT_DIR+set}" != "set" ] || GIT_DIR="."
27 # Get out of the mob
28 case "$PWD" in *?/mob)
29 cd ..
30 GIROCCO_PERSONAL_MOB=1
31 esac
33 mob=@mob@
34 umask 002
35 git config gitweb.lastchange "$(date '+%a, %d %b %Y %T %z')" || :
36 git for-each-ref --sort=-committerdate --format='%(committerdate:iso8601)' \
37 --count=1 refs/heads >info/lastactivity || :
38 ! [ -d htmlcache ] || { >htmlcache/changed; } 2>/dev/null || :
39 rm -f .delaygc .allowgc
40 if [ "$mob" = "mob" ] && [ -d mob ]; then
41 git for-each-ref --format='%(objectname) %(refname)' >packed-refs.mob.$$ || :
42 mv -f packed-refs.mob.$$ packed-refs.mob
43 rm -f packed-refs.mob.$$
46 sockpath=/etc/taskd.socket
47 reporoot=/@jailreporoot@
48 authuser="$LOGNAME"
49 cwd="$(pwd -P)"
50 if [ -x @perlbin@ ]; then
51 # Not in chroot...
52 . @basedir@/shlib.sh
54 sockpath="$cfg_chroot$sockpath"
55 reporoot="$cfg_reporoot"
57 # authuser needs to be set if not running in the chroot.
58 # Currently that can only be the case with https push in
59 # which case REMOTE_USER will contain the user name (possibly prefixed
60 # with "/UID=" and suffixed with "/dnQualifier=...").
61 # Fallback is the mirror_user if REMOTE_USER is not set.
62 authuser="${REMOTE_USER#/UID=}"
63 authuser="${authuser%/dnQualifier=*}"
64 [ -n "$authuser" ] || authuser="%$cfg_mirror_user%"
65 else
66 # In chroot...
67 nc_openbsd() { /bin/nc.openbsd "$@"; }
69 reporoot="$(cd "$reporoot" && pwd -P)"
70 projname="${cwd#$reporoot/}"
72 if [ -n "$GIROCCO_PERSONAL_MOB" ] || ! [ -S "$sockpath" ]; then
73 # We never run the ref update notification part on a personal mob push
74 # Read the incoming refs, but just ignore them (git doesn't like SIGPIPE)
75 while read -r line; do
77 done
78 else
80 trap ':' PIPE
81 echo "ref-changes $authuser ${projname%.git}" || :
82 while read -r line; do
83 echo "$line" || :
84 done
85 git for-each-ref --format='%(objectname) %(objectname) %(refname)' refs/heads || :
86 echo "done ref-changes $authuser ${projname%.git}" || :
87 ) 2>/dev/null | { nc_openbsd -w 15 -U "$sockpath" || :; } || :
90 exit 0