1 | #!/bin/bash |
2 |
|
3 | # .git/hooks/pre-receive |
4 |
|
5 | SCRIPTPATH=$(dirname $(realpath -s $0)) |
6 |
|
7 | while read oldrev newrev ref |
8 | do |
9 | echo "Ref $ref received. Checking for pre-receive hook modification..." |
10 | if [[ $(! git diff --name-only $oldrev $newrev | grep pre-receive) ]]; then |
11 | echo "Updated pre-receive hook detected. Installing..." |
12 | mkdir -p /tmp/newrev |
13 | git archive $newrev | tar -x -C /tmp/newrev |
14 | mv /tmp/newrev/pre-receive $SCRIPTPATH/pre-receive |
15 | rm -rf /tmp/newrev |
16 | echo "Running new pre-receive hook." |
17 | echo "$oldrev $newrev $ref" | $SCRIPTPATH/pre-receive |
18 | echo "Done running new pre-receive hook." |
19 | exit $? |
20 | else |
21 | echo "No pre-receive hook modification." |
22 | fi |
23 | echo "Ref $ref received. Checking for post-receive hook modification..." |
24 | if [[ $(! git diff --name-only $oldrev $newrev | grep post-receive) ]]; then |
25 | echo "Updated post-receive hook detected. Installing..." |
26 | mkdir -p /tmp/newrev |
27 | git archive $newrev | tar -x -C /tmp/newrev |
28 | mv /tmp/newrev/post-receive $SCRIPTPATH/post-receive |
29 | rm -rf /tmp/newrev |
30 | else |
31 | echo "No post-receive hook modification." |
32 | fi |
33 | done |
34 |
|