Problems:
- Source codes syntax highlight stops working for long file (not too long actually). I can split my script to many parts, but it’s a bit troublesome.
- Bash codes cannot handle multiple-line string properly.
cat <<EOT > post-receive
#!/bin/bash
while read oldrev newrev ref
do
if [[ \$ref =~ .*/master$ ]] ; then
echo "Master ref received. Deploying master branch to production..."
git --work-tree=$USER_ROOT/$1/$2 --git-dir=$GIT_ROOT/$1/$2.git checkout -f
git --work-tree=$USER_ROOT/$1/$2 --git-dir=$GIT_ROOT/$1/$2.git clean -d -f
chown -R $1 $USER_ROOT/$1/$2
else
echo "Ref \$ref successfully received. Doing nothing: only the master branch can be deployed on this server."
fi
done
EOT
chmod +x post-receive