public
Created

Git post receive update site

  • Download Gist
post-receive.sh
Shell
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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
#!/bin/sh
#
# An example hook script for the "post-receive" event.
#
# The "post-receive" script is run after receive-pack has accepted a pack
# and the repository has been updated. It is passed arguments in through
# stdin in the form
# <oldrev> <newrev> <refname>
# For example:
# aa453216d1b3e49e7f6f98441fa56946ddcd6a20 68f7abf4e6f922807889f52bc043ecd31b79f814 refs/heads/master
#
# see contrib/hooks/ for a sample, or uncomment the next line and
# rename the file to "post-receive".
 
#. /usr/share/git-core/contrib/hooks/post-receive-email
 
GIT_NAME="Site"
GIT_PATH=/var/www/site/
GIT_BRANCH=live
 
GIT_USER=git
GIT_GROUP=www-data
GIT_FILE_MOD=664
GIT_DIR_MOD=775
 
 
echo "** UPDATING $GIT_NAME **"
cd $GIT_PATH
if [ $? != 0 ]; then
echo "cd to $GIT_PATH failed. Exit"
exit 1
fi
 
unset GIT_DIR
 
git fetch origin $GIT_BRANCH
files=`git diff ..FETCH_HEAD --name-only --diff-filter=ACMRTUXB`
git merge FETCH_HEAD
 
git submodule update
 
#change file owner an permissions
for file in $files
do
chown $GIT_USER:$GIT_GROUP $file
if [ -d "$file" ]
then
chmod $GIT_DIR_MOD $file
else
chmod $GIT_FILE_MOD $file
fi
done
echo "** $GIT_NAME UPDATED**"

TODO:
First commit error:
remote: * branch master -> FETCH_HEAD
remote: fatal: ambiguous argument '..FETCH_HEAD': unknown revision or path not in the working tree.
remote: Use '--' to separate paths from revisions

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.