hooks: truly find ourselves
[girocco/readme.git] / hooks / post-receive
blob2f684edde8da310098875fa030b2b25519224cb2
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" ] || { [ -n "$GIT_DIR" ] && [ -d "$GIT_DIR" ]; } || unset GIT_DIR
13 [ -n "$GIT_DIR" ] || GIT_DIR="$(git rev-parse --git-dir)"
14 [ -n "$GIT_DIR" ] && cd -P "${GIT_DIR:-.}" || exit 1
15 case "${PWD%/*}" in */worktrees)
16 # Gah!
18 # But it COULD just be a coincidence...
19 [ -s commondir ] && [ -s HEAD ] &&
20 _cmndir= && read -r _cmndir <commondir 2>/dev/null &&
21 [ -n "$_cmndir" ] && [ -d "$_cmndir" ]
22 then
23 # ...it is not, fix it!
24 cd -P "$_cmndir" || exit 1
26 esac
27 GIT_DIR="." GIT_PREFIX= && export GIT_DIR
29 # Get out of the mob
30 case "$PWD" in *?/mob)
31 cd ..
32 GIROCCO_PERSONAL_MOB=1
33 esac
35 mob=@mob@
36 autogchack=@autogchack@
37 umask 002
38 git config gitweb.lastchange "$(date '+%a, %d %b %Y %T %z')" || :
39 git for-each-ref --sort=-committerdate --format='%(committerdate:iso8601)' \
40 --count=1 refs/heads >info/lastactivity || :
41 ! [ -d htmlcache ] || { >htmlcache/changed; } 2>/dev/null || :
42 rm -f .delaygc .allowgc
43 if [ "$mob" = "mob" ] && [ -d mob ]; then
44 git for-each-ref --format='%(objectname) %(refname)' >packed-refs.mob.$$ || :
45 mv -f packed-refs.mob.$$ packed-refs.mob
46 rm -f packed-refs.mob.$$
49 sockpath=/etc/taskd.socket
50 authuser="$LOGNAME"
51 if [ -x @perlbin@ ]; then
52 # Not in chroot...
53 . @basedir@/shlib.sh
55 sockpath="$cfg_chroot$sockpath"
56 v_get_proj_from_dir projname
58 # authuser needs to be set if not running in the chroot.
59 # Currently that can only be the case with https push in
60 # which case REMOTE_USER will contain the user name (possibly prefixed
61 # with "/UID=" and suffixed with "/dnQualifier=...").
62 # Fallback is the mirror_user if REMOTE_USER is not set.
63 authuser="${REMOTE_USER#/UID=}"
64 authuser="${authuser%/dnQualifier=*}"
65 [ -n "$authuser" ] || authuser="%$cfg_mirror_user%"
66 else
67 # In chroot...
68 reporoot=/@jailreporoot@
69 reporoot="$(cd "$reporoot" && pwd -P)"
70 cwd="$(pwd -P)"
71 projname="${cwd#$reporoot/}"
73 nc_openbsd() { /bin/nc.openbsd "$@"; }
77 [ "${autogchack:-0}" != "0" ] &&
78 { [ "$cfg_autogchack" != "mirror" ] || ! [ -e .nofetch ]; } &&
79 [ "$(git config --get --bool girocco.autogchack 2>/dev/null)" != "false" ]
80 then
81 git for-each-ref --format '%(refname) %(objectname)' | LC_ALL=C sort -b -k1,1 >.refs-new.$$
82 mv -f .refs-new.$$ .refs-last
83 rm -f .refs.new.$$
86 if [ -n "$GIROCCO_PERSONAL_MOB" ] || ! [ -S "$sockpath" ]; then
87 # We never run the ref update notification part on a personal mob push
88 # Read the incoming refs, but just ignore them (git doesn't like SIGPIPE)
89 while read -r line; do
91 done
92 else
93 trap ':' PIPE
95 echo "ref-changes $authuser ${projname%.git}" || :
96 while read -r line; do
97 echo "$line" || :
98 done
99 git for-each-ref --format='%(objectname) %(objectname) %(refname)' refs/heads || :
100 echo "done ref-changes $authuser ${projname%.git}" || :
101 ) 2>/dev/null | { nc_openbsd -w 15 -U "$sockpath" || :; } || :
102 trap - PIPE
105 exit 0