1 | #!/bin/bash |
2 |
|
3 | # .git/hooks/pre-receive |
4 |
|
5 | SCRIPTPATH=$(dirname $(realpath -s $0)) |
6 | BRANCH="master" |
7 |
|
8 | while read oldrev newrev ref |
9 | do |
10 | if [ "$ref" = "refs/heads/$BRANCH" ]; |
11 | then |
12 | echo "Ref $ref received. Deploying ${BRANCH} branch to production..." |
13 | if [ ! git diff --name-only $1..$2 | grep 'post-receive' ]; then |
14 | echo "Updated post-receive hook detected. Installing..." |
15 | git archive $newrev | tar -x -C /tmp/newrev |
16 | cp /tmp/newrev/post-receive $SCRIPTPATH/post-receive |
17 | rm -rf /tmp/newrev |
18 | fi |
19 | else |
20 | echo "Ref $ref received. Doing nothing: only the ${BRANCH} branch may be deployed on this server." |
21 | fi |
22 | done |
23 |
|