2

So I got a GIT repository with a couple of submodules. Now i created a "post-update" hook on my webserver that automatically deploys my website on update.

That's how my post-update hook looks like:

#!/bin/sh
rm -rf /home/my_user/public_html/my_website/*
unset GIT_INDEX_FILE
export GIT_WORK_TREE=/home/my_user/public_html/my_website/
export GIT_DIR=/home/my_user/gitrepos/my_website.git
git checkout -f

Everything works nicely apart from the fact that the submodules directories are not exported... And that is my question. How can I deploy a GIT repository and it's submodules through the post-update hook?

Thanks in advance!

1

It should work, except you could add, for taking care of those submodules:

git submodule init
git submodule update

See also Using git submodule update --init on a post hook if you have error messages.

1

Alright I made a script that avoids the use of a non-bare repository and receive.denyCurrentBranch ignore

#!/bin/sh

# DIR VARS
DIR_GIT="/home/my_user/gitrepos/my_repo.git"
DIR_HTTP="/home/my_user/public_html/my_website"

unset GIT_DIR

# Recreate HTTP dir
rm -rf $DIR_HTTP
mkdir $DIR_HTTP

# Clone git repository
git clone $DIR_GIT $DIR_HTTP

# import submodules
cd $DIR_HTTP
git init --bare $DIR_HTTP
git submodule init
git submodule update

# delete unnecessary git repository in http dir
rm -rf $DIR_HTTP/.git

Any improvements are welcome

  • Nice feedback, more practical than my own answer. +1 – VonC Jan 3 '13 at 19:38

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.