Git全局钩子定制

发布于 2024-10-02 10:22:50 字数 728 浏览 5 评论 0原文

我计划编写一些 git hooks 作为一个项目,将用户的操作记录在数据库中。然后可以使用该数据库来查询他的所有活动。我试图记录的操作是

  • 提交
  • 、拉
  • 合并
  • 分支,

我想将其打包到可以通过包管理器安装的发行版中。 Git 通过在 $PREFIX/share/templates/hooks 中放置任何此类钩子来允许全局钩子。

目前,有一些钩子被禁用(.sample 附加到它们的名称中)。创建新存储库时,这些挂钩将被复制到存储库的 .git 文件夹中。

现在,如果用户安装了这些挂钩的软件包以及诸如 post-commit更新后已启用。在这种情况下,脚本文件将被覆盖!这听起来很糟糕

这意味着 git 每个操作只有一个钩子文件。如果我需要为一个动作保留三个钩子,那就意味着这是不可能的。这意味着从包管理器自动安装可能会引入冲突。

现在认为我们打包了钩子来覆盖默认启用的文件。如果用户想要向这些文件添加更多操作,然后决定卸载我的软件包,那么他的自定义命令也会消失吗?

我认为 git 在这方面非常聪明,但我错了:(

需要有一个名为 post-commitpost-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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你怎么敢 2024-10-09 10:22:50

为什么不编写一个提交后挂钩(例如)来查找“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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文