GIT post-receive hook不检查子模块

Jas*_*han 3 git kohana-3

我一直在研究我之前使用下载的zip文件安装的Kohana 3项目.我的远程服务器"project.git"上有一个git存储库,它检查工作目录"public_html"的最新提交,我在那里测试应用程序

我的post-receive挂钩文件

GIT_WORK_TREE=/var/www/public_html;
git checkout -f;
Run Code Online (Sandbox Code Playgroud)

这工作了几个月,直到我决定删除一些kohana文件夹并使用git子模块,所以我可以通过git做更新.

现在的问题是子模块不在工作目录中.我尝试去那里添加子模块,但"public_html"目录不是存储库.在"project.git"目录中,git命令抛出一个错误,我必须在工作目录中执行它们.

在提交时如何修改我的钩子以检查子模块?

更新

根据@ manojlds的建议:我将它添加到钩子中,现在它看起来像这样:

GIT_WORK_TREE=/var/www/public_html;
git submodule init;
git submodule update; 
git checkout -f;
Run Code Online (Sandbox Code Playgroud)

但我得到这个消息,

remote: You need to run this command from the Top level of the working tree
Run Code Online (Sandbox Code Playgroud)

并没有改变子模块

public_html
Run Code Online (Sandbox Code Playgroud)

man*_*lds 5

您必须添加以下内容(适当地使用GIT_WORK_TREE环境变量):

git submodule init
git submodule update
Run Code Online (Sandbox Code Playgroud)

这样您就可以获取远程服务器上子模块的内容,然后将它们复制到 public_html

以下是完整的post-receive钩子(经过修改以支持子模块的正常运行):

#!/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
Run Code Online (Sandbox Code Playgroud)