hooks: work around worktree wierdness
[girocco.git] / hooks / post-receive
blob02316147acf423ca56d55d7a047b469e02fbeb08
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 mob=@mob@
28 umask 002
29 git config gitweb.lastchange "$(date '+%a, %d %b %Y %T %z')" || :
30 git for-each-ref --sort=-committerdate --format='%(committerdate:iso8601)' \
31 --count=1 refs/heads >info/lastactivity || :
32 ! [ -d htmlcache ] || { >htmlcache/changed; } 2>/dev/null || :
33 rm -f .delaygc .allowgc
34 if [ "$mob" = "mob" ] && [ -d mob ]; then
35 git for-each-ref --format='%(objectname) %(refname)' >packed-refs.mob.$$ || :
36 mv -f packed-refs.mob.$$ packed-refs.mob
37 rm -f packed-refs.mob.$$
40 sockpath=/etc/taskd.socket
41 reporoot=/@jailreporoot@
42 authuser="$LOGNAME"
43 cwd="$(pwd -P)"
44 if [ -x @perlbin@ ]; then
45 # Not in chroot...
46 . @basedir@/shlib.sh
48 sockpath="$cfg_chroot$sockpath"
49 reporoot="$cfg_reporoot"
51 # authuser needs to be set if not running in the chroot.
52 # Currently that can only be the case with https push in
53 # which case REMOTE_USER will contain the user name (possibly prefixed
54 # with "/UID=" and suffixed with "/dnQualifier=...").
55 # Fallback is the mirror_user if REMOTE_USER is not set.
56 authuser="${REMOTE_USER#/UID=}"
57 authuser="${authuser%/dnQualifier=*}"
58 [ -n "$authuser" ] || authuser="%$cfg_mirror_user%"
59 else
60 # In chroot...
61 nc_openbsd() { /bin/nc.openbsd "$@"; }
63 reporoot="$(cd "$reporoot" && pwd -P)"
64 projname="${cwd#$reporoot/}"
66 if [ -n "$GIROCCO_PERSONAL_MOB" ] || ! [ -S "$sockpath" ]; then
67 # We never run the ref update notification part on a personal mob push
68 # Read the incoming refs, but just ignore them (git doesn't like SIGPIPE)
69 while read -r line; do
71 done
72 else
74 trap ':' PIPE
75 echo "ref-changes $authuser ${projname%.git}" || :
76 while read -r line; do
77 echo "$line" || :
78 done
79 git for-each-ref --format='%(objectname) %(objectname) %(refname)' refs/heads || :
80 echo "done ref-changes $authuser ${projname%.git}" || :
81 ) 2>/dev/null | { nc_openbsd -w 15 -U "$sockpath" || :; } || :
84 exit 0