aboutsummaryrefslogtreecommitdiff
path: root/create-git-hooks.sh
blob: e2c61a6480b882e7d62d558999b0838334b4507f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/bash
# create-git-hooks.sh
# Author: Chris Jones <cmsj@canonical.com>
# Copyright 2011 Canonical Ltd. All Rights Reserved.

OWNER="git"
GROUP="git"
GITPATH="/srv/repositories/"
HOOK="exec git update-server-info"
NOUPDATE="# NO AUTOMATIC MODIFICATIONS"

for path in $(find -L $GITPATH -type d -name hooks) ; do
    HOOKFILE="${path}/post-update"
    if [ ! -f $HOOKFILE ]; then
        # hook file is not correct, make it correct
        cat <<EOF >$HOOKFILE
#!/bin/sh
# see https://git.linaro.org/infrastructure/linaro-git-tools.git

#-pfalcon 2013-11-14
date >>/tmp/git-post-update.log
echo "Running git post-update hook for $GIT_DIR" >>/tmp/git-post-update.log

exec git update-server-info
EOF
        OWNERGROUP="$OWNER:$GROUP"
        git --git-dir=${path}/../ --work-tree=${path}/../../ update-server-info
        chown $OWNERGROUP $HOOKFILE
        chmod +x $HOOKFILE

        if [ -e  "${path}/../info/refs" ];then
            chown $OWNERGROUP ${path}/../info/refs
        fi
        if [ -e  "${path}/../info/objects/packs" ];then
            chown $OWNERGROUP ${path}/../objects/packs
        fi
    fi
done