I'm working on the post-receive of my git server so that it automatically uploads the latest version of my website in a folder named after the branch that the commit was in, but somehow doing this code doesn't work as intended.
Somehow my value branch gets the values of all the branches instead of the branch I'm trying to get. Hash does get the right hash code. I have tested it outside of the program, so does branch when I type the right hash. Did I use the wrong syntax in this program?
#!/bin/sh
hash=$(git log -n 1 --pretty=format:"%h")
branch=$(git branch --contains $(git log -n 1 --pretty=format:"%H"))
if [ branch ]
then
GIT_WORK_TREE="/data/site/'$branch'"
echo "/data/site/'$branch'"
git checkout -f $branch
fi