GIT post-receive hook not checking out submodules

白昼怎懂夜的黑 提交于 2019-12-03 17:32:38

This is my post-receive hook: Replace WORK_DIR with a location where you want to checkout to. This is a main web directory in my case. It is initialized as a git repository and simply pulls from the git bare repository this hooks runs in. This solves both the checkout speed (git is much faster in checking out than cp -R from the other answer is) and also keeps submodules properly synced.

#!/bin/sh
unset GIT_DIR
echo "Checking out"
(cd $WORK_DIR && git pull --recurse-submodules=yes --force)
echo "Submodule update..."
(cd $WORK_DIR && git --work-tree="$WORK_DIR" submodule update --init --recursive --force)

You have to add the following (appropriately using the GIT_WORK_TREE environment varible):

git submodule init
git submodule update

so that you can get the contents of the submodules on the remote server and then copy them to public_html

The below is the full post-receive hook ( modified to support proper functioning of the submodules) :

#!/bin/sh
unset GIT_DIR
git clone /path/to/repo /tmp/public_html
cd /tmp/public_html
git submodule init
git submodule update
cp -R /tmp/public_html /var/www/
rm -rf /tmp/public_html
rm -rf /var/www/public_html/.git
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!