User Tools

Site Tools


git_hooks

This is an old revision of the document!


Git Hooks

pre-receive Hook (Server-Side)

This is a hook i use along with Gitlab. Its global and will be triggerd for all repositories when data ist send to the server. For Gitlab Omnibus installations place 'pre-receive' file in this Folder (if it does not exist, create it)

/opt/gitlab/embedded/service/gitlab-shell/hooks/pre-receive.d/

Make sure the file ist executable using 'chmod +x pre-receive'

pre-receive
#!/bin/sh
 
read oldrev newrev refname wusel
 
merges=`git log --oneline --merges $oldrev..$newrev`
 
readarray -t COMMIT <<< "$merges"
 
if [ -z "$COMMIT" ]; then
    # IF ARRAY EMPTY
    # echo ">>>>>" $COMMIT "<<<<<"
    exit 0
else
    # IF MERGE EXISTS
    for i in "$COMMIT"
    do
 
        REGEX_MERGE_DEVELOP="\bMerge.*?.branch.*?.develop\b"
 
        if [[ $COMMIT =~ $REGEX_MERGE_DEVELOP ]];
        then
 
            echo -e "☠️  ☠️  ☠️  ☠️  ☠️  ☠️  ☠️  ☠️  ☠️  ☠️  ☠️  ☠️  ☠️  ☠️"
        	echo -e "\e[31m"
        	echo -e "Please do not merge 'develop' into any other branch \e[0m"
        	echo -e "Review your commit:"
        	echo -e ""
 
            for i in "$COMMIT"
            do        	
            	echo -e "  $COMMIT"
            done
 
        	echo -e ""
            echo -e "☠️  ☠️  ☠️  ☠️  ☠️  ☠️  ☠️  ☠️  ☠️  ☠️  ☠️  ☠️  ☠️  ☠️"
 
        	exit 1
        else
            exit 0
        fi
    done
fi
git_hooks.1508395222.txt.gz · Last modified: 2017/10/19 08:40 by admin