Git全局钩子定制
我计划编写一些 git hooks 作为一个项目,将用户的操作记录在数据库中。然后可以使用该数据库来查询他的所有活动。我试图记录的操作是
- 提交
- 、拉
- 推
- 合并
- 分支,
我想将其打包到可以通过包管理器安装的发行版中。 Git 通过在 $PREFIX/share/templates/hooks 中放置任何此类钩子来允许全局钩子。
目前,有一些钩子被禁用(.sample
附加到它们的名称中)。创建新存储库时,这些挂钩将被复制到存储库的 .git 文件夹中。
现在,如果用户安装了这些挂钩的软件包以及诸如 post-commit
和更新后
已启用。在这种情况下,脚本文件将被覆盖!这听起来很糟糕
这意味着 git 每个操作只有一个钩子文件。如果我需要为一个动作保留三个钩子,那就意味着这是不可能的。这意味着从包管理器自动安装可能会引入冲突。
现在认为我们打包了钩子来覆盖默认启用的文件。如果用户想要向这些文件添加更多操作,然后决定卸载我的软件包,那么他的自定义命令也会消失吗?
我认为 git 在这方面非常聪明,但我错了:(
需要有一个名为 post-commit
和 post-update
的文件夹或 git 应该执行的任何操作运行该文件夹中的所有脚本我仍在寻找一种方法来处理当前情况。
I am planning to write a few git hooks as a project which logs the user's actions in a database. This database can then be used for querying for all his activities. The actions I am trying to log are
- commit
- pull
- push
- merge
- branch
I want to get this packaged in distros which can be installed via package manager.
Git allows global hooks by placing any such in $PREFIX/share/templates/hooks
It currently has some hooks which are disabled (.sample
is appended to their name). When a new repository is created, these hooks are copied in the .git
folder of the repository
Now if a user installs the package for these hooks and hooks like post-commit
and post-update
are already enabled. In this case the script file will be overwritten! This sounds bad
This means git has only one hook file per action. If I need to keep three hooks for one action, it means it is not possible. This means automated install from package manager can introduce conflicts.
Now think that we packaged the hooks to overwrite the default enabled file. If a user wants to add some more actions to those file and then decided to uninstall my package, then his custom command would also be gone?
I thought that git was pretty clever in this regard and I was wrong :(
There needs to be a folder named post-commit
and post-update
or whatever actions and git should run all the scripts inside that folder. I am still hunting a way to deal with the current situation.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么不编写一个提交后挂钩(例如)来查找“post-commit-hooks”子目录并列出并执行在其中找到的所有脚本?
(第一个未成功运行的将导致所有提交后挂钩失败)
如果用户初始化其 来自预定义模板目录的 Git 存储库,然后您可以确保它们都在新存储库中获取这些特殊脚本。
Why not write a post-commit hook (for instance) that will look for a "post-commit-hooks" subdirectory and will list and execute all scripts find in it?
(the first one that doesn't run successfully will fail the all post-commit hook)
If the users initialize their Git repo from a predefined template directory, you can then make sure they all get those special scripts in their new repo.