toolbox/update-all-config.pl: quiet means quiet
[girocco.git] / hooks / post-receive
blob741859b9a3d05cb518b28b5845314e8a3478a028
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 if ! [ -x @perlbin@ ]; then
12 # We are INSIDE the chroot
13 PATH=/bin && export PATH
16 # Make sure the current directory is where we expect to be
17 [ "${GIT_DIR+set}" != "set" ] || { [ -n "$GIT_DIR" ] && [ -d "$GIT_DIR" ]; } || unset GIT_DIR
18 [ -n "$GIT_DIR" ] || GIT_DIR="$(git rev-parse --git-dir)"
19 [ -n "$GIT_DIR" ] && cd -P "${GIT_DIR:-.}" || exit 1
20 case "${PWD%/*}" in */worktrees)
21 # Gah!
23 # But it COULD just be a coincidence...
24 [ -s commondir ] && [ -s HEAD ] &&
25 _cmndir= && read -r _cmndir <commondir 2>/dev/null &&
26 [ -n "$_cmndir" ] && [ -d "$_cmndir" ]
27 then
28 # ...it is not, fix it!
29 cd -P "$_cmndir" || exit 1
31 esac
32 GIT_DIR="." GIT_PREFIX= && export GIT_DIR
34 # Get out of the mob
35 case "$PWD" in *?/mob)
36 cd ..
37 GIROCCO_PERSONAL_MOB=1
38 esac
40 mob=@mob@
41 autogchack=@autogchack@
42 umask 002
43 git config gitweb.lastchange "$(date '+%a, %d %b %Y %T %z')" || :
44 git for-each-ref --sort=-committerdate --format='%(committerdate:iso8601)' \
45 --count=1 refs/heads >info/lastactivity || :
46 ! [ -d htmlcache ] || { >htmlcache/changed; } 2>/dev/null || :
47 rm -f .delaygc .allowgc
48 if [ "$mob" = "mob" ] && [ -d mob ]; then
49 git for-each-ref --format='%(objectname) %(refname)' >packed-refs.mob.$$ || :
50 mv -f packed-refs.mob.$$ packed-refs.mob
51 rm -f packed-refs.mob.$$
54 sockpath=/etc/taskd.socket
55 authuser="$LOGNAME"
56 if [ -x @perlbin@ ]; then
57 # We are NOT inside the chroot
58 . @basedir@/shlib.sh
60 sockpath="$cfg_chroot$sockpath"
61 v_get_proj_from_dir projname
63 # authuser needs to be set if not running in the chroot.
64 # Currently that can only be the case with https push in
65 # which case REMOTE_USER will contain the user name (possibly prefixed
66 # with "/UID=" and suffixed with "/dnQualifier=...").
67 # Fallback is the mirror_user if REMOTE_USER is not set.
68 authuser="${REMOTE_USER#/UID=}"
69 authuser="${authuser#UID = }"
70 authuser="${authuser%/dnQualifier=*}"
71 authuser="${authuser%, dnQualifier = *}"
72 [ -n "$authuser" ] || authuser="%$cfg_mirror_user%"
73 else
74 # In chroot...
75 reporoot=/@jailreporoot@
76 reporoot="$(cd "$reporoot" && pwd -P)"
77 cwd="$(pwd -P)"
78 projname="${cwd#$reporoot/}"
80 nc_openbsd() { /bin/nc.openbsd "$@"; }
84 [ "${autogchack:-0}" != "0" ] &&
85 { [ "$cfg_autogchack" != "mirror" ] || ! [ -e .nofetch ]; } &&
86 [ "$(git config --get --bool girocco.autogchack 2>/dev/null)" != "false" ]
87 then
88 git for-each-ref --format '%(refname) %(objectname)' | LC_ALL=C sort -b -k1,1 >.refs-new.$$
89 mv -f .refs-new.$$ .refs-last
90 rm -f .refs.new.$$
93 if [ -n "$GIROCCO_PERSONAL_MOB" ] || ! [ -S "$sockpath" ]; then
94 # We never run the ref update notification part on a personal mob push
95 # Read the incoming refs, but just ignore them (git doesn't like SIGPIPE)
96 while read -r line; do
98 done
99 else
100 # Check to see if we've lost our HEAD
101 if ! git rev-parse --verify HEAD >/dev/null 2>&1; then
102 git config --unset girocco.headok >/dev/null 2>&1 || :
104 trap ':' PIPE
106 echo "ref-changes $authuser ${projname%.git}" || :
107 while read -r line; do
108 echo "$line" || :
109 done
110 git for-each-ref --format='%(objectname) %(objectname) %(refname)' refs/heads || :
111 echo "done ref-changes $authuser ${projname%.git}" || :
112 ) 2>/dev/null | { nc_openbsd -w 15 -U "$sockpath" || :; } || :
113 trap - PIPE
116 exit 0