Git Post Receive Hook: update current working branch to staging server
Asked Answered
C

1

2

So, I have a staging server setup, and what I would like to do is when someone pushes to a non master branch update what the staging server's directory. My current post-receive hook looks like:

echo "post hook is on the run!"

while read oldrev newrev ref
do
    echo "$ref"
done

unset $(git rev-parse --local-env-vars)
cd ../staging/bikereport
git fetch
git pull origin $ref

echo "Post receive finsihed"

However I am not seeing the changes I would like on the server, and remote returns "Already up-to-date" which makes me think it's pulling from Master or something?

This isn't an elegant solution, but we are a very small team working on a single project. An ideal solution would be to save every branch to a new directory within the staging server and then update only that directory per push.

Corrinecorrinne answered 6/7, 2013 at 17:12 Comment(0)
D
2
cd ../staging/bikereport
git fetch

Beware: your git directory is not your staging/bikereport repo.
It is still the one where the hook is running.

You need to set GIT_DIR to /full/path/ofstaging/bikereport/.git (and to be sure, set GIT_WORK_TREE to /full/path/ofstaging/bikereport) in order for commands run from that repo to work.
And you need to unset GIT_INDEX_FILE!

See "Why doesn't setting GIT_WORK_TREE work in a post-commit hook?" for more details.

You hook should start with:

#!/bin/sh
 unset GIT_INDEX_FILE
 export GIT_WORK_TREE=/full/path/ofstaging/bikereport/
 export GIT_DIR=/full/path/ofstaging/bikereport/.git/
Duquette answered 6/7, 2013 at 17:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.