Finally I have come out with this script to check out files to different 
workdirs (depending on branch) after push.
I merged some suggestions I found on the net and this script seems to work 
fine.

post-receive hook script:
#!/bin/sh

    export GIT_DIR=/home/git/site-bare.git/
    
    echo "GIT DIR:  $GIT_DIR";
    echo "\n";
    
    # export GIT_TRACE=1
    cd $GIT_DIR

while read oldrev newrev refname
do
    branch=$(git rev-parse --abbrev-ref $refname)
    if [ "$branch" = "local_dev" ]; then
        # Do something
        export GIT_WORK_TREE=/home/site/test-workdir/.
        echo "Checking out branch: $branch";
        echo "Checking out to workdir: $GIT_WORK_TREE"; 
        # exit;
        git checkout -f $branch
    fi
    if [ "$branch" = "dev" ]; then
        # Do something
        export GIT_WORK_TREE=/home/site/test-workdir/.
        echo "Checking out branch: $branch";
        echo "Checking out to workdir: $GIT_WORK_TREE"; 
        # exit;
        git checkout -f $branch
    fi
    if [ "$branch" = "master" ]; then
        # Do something
        export GIT_WORK_TREE=/home/site/site_v1_9_13/htdocs/.
        echo "Checking out branch: $branch";
        echo "Checking out to workdir: $GIT_WORK_TREE"; 
        # exit;
        git checkout -f $branch
    fi
done


Posted just for reference, in case somebody needs something similar 
solution.


However I still need to make a change & commit it locally, if I want to 
checkout the remote workdir after the push.
I can not force to checkout the remote workdir after push. There are some 
rare cases, when this would be useful.


Best regards,
Konrad

-- 
You received this message because you are subscribed to the Google Groups "Git 
for human beings" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to git-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to