从接收后 Hook 更新 Git 子模块

标签 git mapping hook git-submodules

我试图在每次提交到 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/

相关文章:

algorithm - 将一个值映射到另一个值并返回

list - F# 在映射时使用先前评估的解决方案(状态)

C# 折叠数组列表

visual-studio-2010 - 通过注入(inject)的 Delphi dll 启用 __fastcall 来 Hook 在 MSVC++ 上制作的应用程序

Git:格式化为正确自动着色 %d

git - 如何在 Gitlab 服务器中记录所有用户的 git 命令( pull/克隆/推...)?

git : give me the repo, 核对本地的一切,我不在乎

node.js - nodegit(用于 Node.js 的 libgit2): How to push and pull?

c++ - 键盘 Hook - 不同的语言 - C++

node.js - Sequelize.js afterFind 参数说明