开发者

Git global hook customization

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 pa开发者_StackOverflow中文版ckage, 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜