3 # Update all out-of-date hooks in all current projects and install missing ones
5 # If one or more project names are given, just update those instead
13 [ "$1" != "--force" ] && [ "$1" != "-f" ] ||
{ force
=1; shift; }
14 [ "$1" != "--dry-run" ] && [ "$1" != "-n" ] ||
{ dryrun
=1; shift; }
15 case "$1" in -*) echo "Invalid options: $1" >&2; exit 1;; esac
18 printf '%s\n' "$(basename "$0"): refusing to run as root -- bad things would happen"
24 base
="${cfg_reporoot%/}"
25 globalhooks
="$base/_global/hooks"
26 hookbin
="$cfg_basedir/hooks"
27 cmd
='cut -d : -f 1 <"$cfg_chroot/etc/group" | grep -v ^_repo'
28 [ $# -eq 0 ] || cmd
='printf "%s\n" "$@"'
31 while read -r proj
; do
34 projdir
="$base/$proj.git"
35 [ -d "$projdir" ] ||
{ echo "$proj: does not exist -- skipping"; continue; }
36 ! [ -e "$projdir/.nohooks" ] ||
{ echo "$proj: .nohooks found -- skipping"; continue; }
38 for hook
in pre-auto-gc pre-receive post-commit post-receive update
; do
40 if [ -f "$projdir/hooks/$hook" ]; then
42 ! [ -L "$projdir/hooks/$hook" ] ||
43 [ "$(readlink "$projdir/hooks
/$hook")" != "$globalhooks/$hook" ]
46 updates
="$updates $hook"
48 elif ! [ -e "$projdir/hooks/$hook" ]; then
49 [ -n "$dryrun" ] ||
[ -d "$projdir/hooks" ] || mkdir
"$projdir/hooks"
51 updates
="$updates +$hook"
53 if [ -z "$dryrun" ] && [ -n "$doln" ]; then
54 ln -sfn "$globalhooks/$hook" "$projdir/hooks/$hook"
57 for hook
in post-update
; do
58 if [ -e "$projdir/hooks/$hook" ]; then
59 [ -n "$dryrun" ] ||
rm -f "$projdir/hooks/$hook"
60 updates
="$updates -$hook"
64 [ -d "$projdir/mob/hooks" ] &&
66 ! [ -L "$projdir/mob/hooks" ] ||
67 [ "$(readlink "$projdir/mob
/hooks
")" != "../hooks" ]
70 if [ -z "$dryrun" ]; then
71 [ -L "$projdir/mob/hooks" ] ||
rm -rf "$projdir/mob/hooks"
72 ln -sfn ..
/hooks
"$projdir/mob/hooks"
74 updates
="$updates mob/hooks@ -> ../hooks"
76 [ -z "$updates" ] ||
echo "$proj:$updates" ${dryrun:+(dryrun)}