1

I'm trying to make git auto deploy to different directories depending on a branch that was pushed. I have a remote bare repository, local repository and two directories where I whant the data to be deployed and updated with each push from local to remote repository. I've added post-update hook:

#!/bin/sh


echo $1
echo "*UPDATE*"


case " $1 " in
*'refs/heads/develop'*)
        GIT_WORK_TREE=/home/git/public_html/example_deploy_dev git checkout develop webroot
        echo
        echo "Dev was pulled"
        echo
        ;;
esac

case " $1 " in
*'refs/heads/master'*)
        GIT_WORK_TREE=/home/git/public_html/example_deploy git checkout master webroot
        echo
        echo "Master was pulled"
        echo
        ;;
esac

It deploys just fine on first file creation, but doesn't update it when it's changed in directories which shold be deployed. Where do I miss smth? Thanks!

Yaroslav Grishajev
  • 2,127
  • 17
  • 22

2 Answers2

0

The usual script for a post update hook is:

#! /bin/sh

update_master() {
    GIT_WORK_TREE=/home/git/public_html/example_deploy_dev git checkout master -- webroot
}

update_develop() {
    GIT_WORK_TREE=/home/git/public_html/example_deploy_dev git checkout develop -- webroot
}
for ref do
    case "$ref" in
    refs/heads/master) update_master;;
    refs/heads/test) update_test;;
    *) ;; # ignore other branches
    esac
done

Since that hook "takes a variable number of parameters, each of which is the name of ref that was actually updated.", you cannot rely only on $1.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • thx for the reply! I had to 'esac' before 'done' to get it working, but it works the same as before: new files are added, but the old ones aren't updated... may be it is somehow relates to permittions?.. – Yaroslav Grishajev Sep 25 '15 at 07:55
  • @YariG it should not, but do you see different ownership/right between new files and old ones in `/home/git/public_html/example_deploy_dev`? – VonC Sep 25 '15 at 08:13
  • @YariG do you need to checkout only webroot? Couldn't you try: `GIT_WORK_TREE=/home/git/public_html/example_deploy_dev git reset --hard` (warning this should override the all folder, not just webroot) – VonC Sep 25 '15 at 10:43
  • sure, I tried it: it updated the directory once but all further pushes behaved the same - adding new files but not updating old ones... – Yaroslav Grishajev Sep 25 '15 at 20:23
0

Try:

checkout -f

#! /bin/sh

update_master() {
    GIT_WORK_TREE=/home/git/public_html/example_deploy_dev git checkout -f master -- webroot
}

update_develop() {
    GIT_WORK_TREE=/home/git/public_html/example_deploy_dev git checkout -f develop -- webroot
}
for ref do
    case "$ref" in
    refs/heads/master) update_master;;
    refs/heads/test) update_test;;
    *) ;; # ignore other branches
    esac
done
Chrims
  • 1