3

I've been playing around with hooks for a while now, but I can't seem to get the post-receive hook to work the way I need it to.

I am trying to get the post-receive hook to create a zip folder and place it somewhere outside the git repository folders after I have pushed my changes to the repository.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
MikeyJ
  • 454
  • 1
  • 5
  • 16

1 Answers1

7

You have a good example of deploying an zip through a post-receive hook in this article from Daniel Byrne:

The idea is to use git archive --format=zip:

#!/bin/bash
#
# A post commit hook that takes any updates pushed to the 'release' branch
# and creates a release directory for the new version under the webroot.
# Live site is then symlinked to this new release directory.

oldrev=$1
newrev=$2
branch=$3

# this is the root of the website (a symlink to a release directory)
webroot=/var/www/danielbyrne.net/www

if [ "$branch" == "release" ]
then

    # create a release directory to extract files into
    target=/var/www/danielbyrne.net/releases/$2/
    mkdir $target

    echo "Making target directory: $target"

    # create an archive in the webroot of danielbyrne.net
    /usr/bin/git archive master --format zip --output $target/deploy.zip

    echo "unzipping archive..."

    # extract the archive
    unzip -o -q $target/deploy.zip -d $target

    echo "removing deployment archive"

    # remove the archive file
    rm $target/deploy.zip

    echo "switching symbolic link to $target"

    # now switch the live site to point to the new release
    ln -nsf $target $webroot

    echo "done";
fi
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I've tried using this but I keep getting the same error i had before which is 'warnign: could not find /tmp, please create' The problem is I've no idea how or where to create '/tmp' – MikeyJ Dec 20 '12 at 13:36
  • @MikeyJ strange, because `/tmp`, as its own names indicates, should be there under `/` (root directory if the server). Maybe a access right issue. – VonC Dec 20 '12 at 14:12
  • Cool to see some of my code referenced on SO :-) @MikeyJ - are you using linux or cgywin on windows? Most distros will have a /tmp directory... at what point do you see the error, and where? – managedheap84 Apr 22 '13 at 16:14
  • @managedheap84 yes, I liked your approach in this hook. Note that MikeJ has last been seen on Stack Overflow last February. You might not get an answer to your question right away ;) – VonC Apr 22 '13 at 18:30