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
 
## EXAMPLE COMMAND: git log --oneline --merges 1bcca583df49bab1388a64730d1647785b3e9b8d..84da95ea03859df818ae23370f83cc80b6ce3972
################## git log --oneline --merges OLDREV..NEWREV
 
merges=`git log --oneline --merges $oldrev..$newrev`
 
echo ----------$("git log --oneline --merges $oldrev..$newrev")
 
readarray -t y <<< "$merges"
 
for i in "${y[@]}"
do
    echo -e "☠️  ☠️  ☠️  ☠️  ☠️  ☠️  ☠️  ☠️  ☠️  ☠️  ☠️  ☠️  ☠️  ☠️\e[31m"
    echo -e "G'Day Mate, what the fuck are you doing?!\nPlease do not merge 'develop' in any other branch \e[0m"
    echo -e "☠️  ☠️  ☠️  ☠️  ☠️  ☠️  ☠️  ☠️  ☠️  ☠️  ☠️  ☠️  ☠️  ☠️"
    exit 1
done

pre-commit Hook

Executed when running “git commit”

pre-commit
#!/bin/sh
 
# LOCATION: MagentoRoot/app/etc/local.xml
mageConfig='../../var/www/clients/web/app/etc/local.xml'
 
# USE MAGNTOs ROOT DIRECTORY
sqlStorage='/root/hook/mysql_structure.sql'
 
# WARNING: cat IS CALLED FOR EACH VARIABLE - TODO: IMPROVE LOGIC/SYNTAX
host=$(cat ${mageConfig} | sed -n '/<connection>/,/<\/connection>/p' | sed -n -e 's/.*<host>\(.*\)<\/host>.*/\1/p' | sed -n -e 's/.*CDATA\[\(.*\)\]\].*/\1/p')
username=$(cat ${mageConfig} | sed -n '/<connection>/,/<\/connection>/p' | sed -n -e 's/.*<username>\(.*\)<\/username>.*/\1/p' | sed -n -e 's/.*CDATA\[\(.*\)\]\].*/\1/p')
password=$(cat ${mageConfig} | sed -n '/<connection>/,/<\/connection>/p' | sed -n -e 's/.*<password>\(.*\)<\/password>.*/\1/p' | sed -n -e 's/.*CDATA\[\(.*\)\]\].*/\1/p')
dbname=$(cat ${mageConfig} | sed -n '/<connection>/,/<\/connection>/p' | sed -n -e 's/.*<dbname>\(.*\)<\/dbname>.*/\1/p' | sed -n -e 's/.*CDATA\[\(.*\)\]\].*/\1/p')
 
echo ''
echo '--> EXPORT SQL STRUCTURE <--'
echo $host
echo $username
echo $password
echo $dbname
echo '--> END - EXPORT SQL STRUCTURE <--'
echo ''
 
# EXPORT SQL STRUCTURE
mysqldump -d -h $host -u $username -p$password $dbname > $sqlStorage
git_hooks.1508220065.txt.gz · Last modified: 2017/10/17 08:01 by admin