Skip to content

Instantly share code, notes, and snippets.

@jnslxndr
Forked from owahab/post-update
Created April 6, 2012 11:09
Show Gist options
  • Save jnslxndr/2318926 to your computer and use it in GitHub Desktop.
Save jnslxndr/2318926 to your computer and use it in GitHub Desktop.
#!/bin/sh
#
# This hook does two three things:
#
# 1. update the "info" files that allow the list of references to be
# queries over dumb transports such as http
#
# 2. if this repository looks like it is a non-bare repository, and
# the checked-out branch is pushed to, then update the working copy.
# This makes "push" function somewhat similarly to darcs and bzr.
#
# 3. if this looks like it is a non-bare repository, and the pushed
# branch is not checked-out, check it out.
#
# To enable this hook, make this file executable by "chmod +x post-update".
git-update-server-info
is_bare=$(git config --get --bool core.bare)
if [ -z "$is_bare" ]
then
# for compatibility's sake, guess
git_dir_full=$(cd $GIT_DIR; pwd)
case $git_dir_full in */.git) is_bare=false;; *) is_bare=true;; esac
fi
if [ "$is_bare" = "false" ]
then
export GIT_DIR=$(cd $GIT_DIR; pwd)
GIT_WORK_TREE=${GIT_WORK_TREE-..}
for ref
do
echo "Updating remote working directory..."
git reset --hard
git checkout -f $ref
echo "Done!"
echo "Restarting nginx"
/etc/init.d/nginx restart
done
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment