我试图在每次提交到 var/www
super 项目时自动更新位于 var/www/php/vendor/projectX
中的子模块。我在 .git/hooks/post-receive
文件中添加了这些行:
#!/bin/sh
echo "Updating submodules recursively"
pwd
git submodule update --init --recursive
但是当我致力于 super 项目时,我得到了这个:
Counting objects: 8, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 346 bytes | 0 bytes/s, done.
Total 4 (delta 3), reused 0 (delta 0)
remote: Updating submodules recursively
remote: /var/www/.git
remote: No submodule mapping found in .gitmodules for path 'php/vendor/projectX'
To www-data@11.22.33.44:.
3dc2404..bc46dd6 dev -> dev
然而,.gitmodules 文件中存在相应的部分,.git/modules 中的文件也是如此。手动运行 git submodule update --init --recursive
工作正常。只有从钩子(Hook)上运行时它才不起作用。谢谢
最佳答案
尝试并:
- cd 到该 repo 的根文件夹
- 在执行 git 命令时指定该文件夹的工作树和 git 目录。
这将在您的接收后 Hook 脚本中提供:
cd /var/www/
git --git-dir=/var/www/.git --work-tree=/var/www submodule update --init --recursive
关于从接收后 Hook 更新 Git 子模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21535979/