Using git hook after commit

I just started writing a web application.

I use GIT for version control, and I have GIT and a web server on the same computer.

The application has 3 environments: dev, test and production

I want to use a GIT hook after each commit to update a dev, test or production application.

What is the best practice for this?

I need something like this:

  • when i commit dev should automatically update
  • when the commit message contains "test:" before the message, dev and the test must be updated.
  • when the commit message contains "production:" before the message - production, dev and test must be updated.

Thank!

+5
3

hook/mini bash script,

#!/bin/bash

if git log --pretty=format:%s -1 | grep -q "^test: "
then
    #action / update dev/test
elif git log --pretty=format:%s -1 | grep -q "^production: "
then
    #action / update dev/test/production
else
    #action / update dev
fi

bash script, .. , :)

+1

, - ...

#!/bin/bash

MESSAGE=$(git log -1 HEAD --pretty=format:%s)

if [[ "$MESSAGE" == *\[staging\]* ]];
then
    #action / update staging
    # another method not being used...
    # GIT_WORK_TREE=/path/to/working/site/ git checkout -q -f staging
    echo "NOTE: Beginning Auto-Push to Staging Server... "
    `git push staging`
    echo "========================================================
======== Done! Pushed to STAGING.com  ============= 
======== Thanks Captain. Keep up the good work! ========
========================================================"
elif [[ "$MESSAGE" == *\[production\]* ]];
then
    #action / update production
    echo "NOTE: Beginning Auto-Push to Production Server... "
    # `git push production`
    echo "========================================================
======== Done!!! Pushed to Production.com  ======= 
======== Test immediately for any errors! =========
========================================================"
fi

:

git push staging ', .git/hooks/post-identive . , umask 002 && & git reset - hard '.

denyrecive .git/config file:

[receive]
    denycurrentbranch = ignore

2:

, ​​ ... (ish) , .

+2

post-commit hook, , - git log -1 --format=%B , git push dev ..

, , post-receive . , , .

, , , , . , .. , test ..

+1

All Articles