I want to setup git for a somewhat unusual use case.
I have a repository server ('repo') and I have a develop server ('develop') I want to deploy to. On the repo server I have a bare repo ('origin') which I push my changes to from my local clone.
When I push a branch called 'development' to the repo server, I have a post-receive hook there that pushes the branch to the development server:
#!/bin/bash
# post-receive on repo server
while read oldrev newrev ref
do
branch=`echo $ref | cut -d/ -f3`
if [ "development" == "$branch" ]; then
git push develop development
echo 'Changes pushed to development server.'
fi
done
exit 0;
On the development server I have a post-receive hook that reads
#!/bin/bash
GIT_WORK_TREE=/srv/www/htdocs/develop git checkout -f
On the develop server it might be the case that someone made changes directly in the the working tree which resides in /srv/www/htdocs/develop without using git (yeah, I know, don't ask…).
Now: What is the best way to prevent the checkout on the develop server which would destroy the non-gitters modifications?
At the moment I simulate this case using a pre-receive hook on the repo server which echoes a message and exits 1.
It would be great if I do
$ git push origin development
and git would answer like so:
Counting objects: 11, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (6/6), done.
Writing objects: 100% (9/9), 706 bytes, done.
Total 9 (delta 3), reused 0 (delta 0)
remote: Unclean working directory on development server. Please fix that first.
To git@repo:development
! [remote rejected] development -> development (pre-receive hook declined)
error: failed to push some refs to git@repo:development'