无法触发git子模块上的提交后git挂钩 [英] Cannot trigger post-commit git hook on git submodule

查看:162
本文介绍了无法触发git子模块上的提交后git挂钩的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们使用一个带有几个子模块的git模块。为了使日常使用更方便,我希望有一个post-commit挂钩,它可以自动将子模块添加到main / super / root git repo / clone / module中的git索引,例如 git添加mychangedsubmodulename ,以便准备好一个提交,以便更新主要repo中子模块的提交引用,并可能提供更多想法。



.git文件夹位于主模块的根文件夹中,并且由于使用 - 递归选项克隆了主要的repo,所以似乎也包含与子模块有关的内容。我的git版本是 git version 2.6.4(Apple Git-63)



我可以轻松创建post-commit钩子,但它不会从子模块中的提交中触发,我认为这是目前为止的正确和适当的措施,但也可能是解决可能的解决方法的线索。



我试图在问题10848191之后的不同位置定义几个post-commit hook文件, a>没有任何成功。



如何在子模块中自动修改主模块?



更新:在子模块post-commit hook现在有效后,我设法通过清理环境变量来进入主存储库并成功调用git。

 #清除git环境或git会在遍历边界时混淆main和sub repos,只通过改变pwd 
而读取变量; do
unset $ variable
完成< <(env | grep^ GIT_| sed's /=.*// g')



<但是,最初的问题是如何触发子模块钩子。这似乎只是有时工作,仍然。

解决方案

你可以在你的post-commit钩子里使用类似下面的东西:



git --work-tree = $ PWD / .. --git-dir = $ PWD /../。git branch $ b

以上命令取自 .git / modules / my-sub-module / hooks / pre-commit file在我的 git版本2.3.2(Apple Git-55)上。我使用上面的命令来列出所有主要仓库的本地分支。



注意:不幸的是,在post-commit钩子中更改目录和运行git-commands可能不会工作,因为git依赖于一些预配置的默认设置和env-vars。所以在我的情况下 cd path-to-main-repo-directory&& git some-command 在我的 .git / modules / my-sub-module / hooks / pre-commit 里没有帮助我。



您也可以查看手册这里了解更多详情。


We use a git module with several submodules. In order to make it more convenient for daily use, I wanted to have a post-commit hook which automatically adds the submodule to the git index in the main/super/root git repo/clone/module such as git add mychangedsubmodulename so as to prepare a commit ready to update the submodule's commit reference in the main repo and probably more ideas to come.

The .git folder is located inside the main module root folder and seems to contain as well the submodule related stuff as a result of having cloned the main repo with --recursive option. My version of git is git version 2.6.4 (Apple Git-63).

I could easily create a post-commit hook in the main repo but it does not fire from commits within a submodule, which I consider correct and appropriate so far but also might be a clue for a possible workaround.

I have tried to define several post-commit hook files in different locations also following the question 10848191 without any success.

How can I achieve to automatically modify the main module on commits in a submodule?

Update: After the submodule post-commit hook now works sometimes, I managed to cd into the main repository and successfully invoke git by cleaning the environment variables.

# clear git environment or git would confuse main and sub repos when crossing boundary by only changing pwd
while read variable; do
    unset $variable
done < <(env | grep "^GIT_" | sed 's/=.*//g')

However, the original question was as how to fire the submodule hook. This seems to be working only sometimes, still.

解决方案

You can use something like below inside your post-commit hook:

git --work-tree=$PWD/.. --git-dir=$PWD/../.git branch

The above command is taken from .git/modules/my-sub-module/hooks/pre-commit file on my git version 2.3.2 (Apple Git-55). I am using the above command to list all the local branches of the main repo.

NOTE: Unfortunately changing directory and running git-commands inside the post-commit hooks may not work, because of the git relying on some of the preconfigured default settings and env-vars. So in my case cd path-to-main-repo-directory && git some-command inside my .git/modules/my-sub-module/hooks/pre-commit did not help me.

You can also check the manual here for more details.

这篇关于无法触发git子模块上的提交后git挂钩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆