GIT_Hooks Template

74 views
Skip to first unread message

InfoTel Multimedia

unread,
Apr 6, 2015, 2:43:29 PM4/6/15
to bonobo-g...@googlegroups.com
I have created a post-receive script to deploy to either a development (master branch) or production (live branch) .. which works great. I would like to have this be automatically included in the Hooks folder when a repo is created. I have mysysgit setup for Bonobo and have found the template directory. That template is used when "git init" is issued, but not when creating the repository with Bonobo.

any suggestions appreciated.

Jakub Chodounský

unread,
Apr 13, 2015, 3:17:36 PM4/13/15
to bonobo-g...@googlegroups.com
Internally Bonobo Git Server uses libgit2 to create repositories, so msysgit is not invoked. I'd prefer using libgit2 for everything, but the server side part needed for http transport is not implemented and probably won't be soon unfortunately.

InfoTel Multimedia

unread,
Jun 19, 2015, 1:31:14 PM6/19/15
to bonobo-g...@googlegroups.com
is there a way to have my post-receive hook automatically included when a repo is created?
I have included the script for anyone who may find it useful.

-- 

#!/bin/sh

    ## pull SITEURL from repository Path
    function repo_name {
        pwd | cut -b 60-
    }
    SITEURL=$(repo_name)

    ## The development directory
    DEPLOYDEVDIR=/[DEV_FOLDER_PATH]/$SITEURL/
    ## The production directory
    DEPLOYPRDDIR=/[PRODUCTION_FOLDER_PATH]/$SITEURL/

    ## Where to store the log info about the updates
    LOGFILE=./post-receive.log
    ## store the arguments given to the script
    read oldrev newrev refname
    ## Record the push received to logfile
    echo -e "Recieved Push Request at $( date +%F )" >> $LOGFILE
    echo " - Old SHA: $oldrev New SHA: $newrev Branch Name: $refname" >> $LOGFILE

    ## deploy development
    function deploy_dev {
        echo "Starting dev.$SITEURL deploy..." &&
        rm -rf $DEPLOYDEVDIR/* && ## flush development directory
        GIT_WORK_TREE="$DEPLOYDEVDIR" git checkout -f &&
        echo "Finished dev.$SITEURL deploy..."
    }

    ## deploy production
    function deploy_prd {
        echo "Starting $SITEURL deploy..." &&
        rm -rf $DEPLOYPRDDIR/* && ## flush production directory
        GIT_WORK_TREE="$DEPLOYPRDDIR" git checkout -f &&
        echo "Finished $SITEURL deploy..."
    }

    ## check if master branch, deploy to DEV if TRUE
    if [ $refname = "refs/heads/master" ]; then
        ## check if development direcotry exists, create if FALSE
        if [ -d "$DEPLOYDEVDIR" ]; then
            echo "dev.$SITEURL directory exists..." &&
            deploy_dev
        else
            echo "dev.$SITEURL directory does not exists..." &&
            echo "Creating dev.$SITEURL directory..." &&
            mkdir $DEPLOYDEVDIR &&
            deploy_dev
        fi
    ## check is live branch, deply to PROD if TRUE
    elif [ $refname = "refs/heads/live" ]; then
        ## check if production directory exists, create if FALSE
        if [ -d "$DEPLOYPRDDIR" ]; then
            echo "$SITEURL direcotry exists..." &&
            deploy_prd
        else
            echo "$SITEURL direcotry does not exist..." &&
            echo "Creating $SITEURL direcotry..." &&
            mkdir $DEPLOYPRDDIR &&
            deploy_prd
        fi
    else
        echo "nothing deployed" &&
        echo "use master (dev) / live (prod) branch(s)"
         
        
    fi

--
Reply all
Reply to author
Forward
0 new messages