Git global binding configuration

I plan to write a few git hooks as a project that logs user actions in the database. Then this database can be used to request all its actions. The actions I'm trying to perform are

  • commit
  • to pull
  • push
  • mergers
  • branch

I want to get this package in distributions, which can be installed through the package manager. Git allows global intercepts by putting any such in $PREFIX/share/templates/hooks

He currently has some interceptors that are disabled ( .sample appended to their name). When a new repository is created, these hooks are copied to the repository's .git folder

Now, if the user installs a package for these hooks, and hooks such as post-commit and post-update are already included. In this case, the script file will be overwritten! That sounds bad.

This means that git has only one file per click per action. If I need to hold three hooks for one action, this means that this is not possible. This means that silent installation from the package manager can lead to conflicts.

Now think that we packed the hooks to overwrite the file with the default enabled. If the user wants to add a few more actions to this file, and then decided to delete my package, will his user command also disappear?

I thought git was pretty smart in this regard, and I was wrong :(

There must be a folder called post-commit and post-update or any actions and git should run all the scripts inside this folder. I am still hunting for a way to handle the current situation.

+6
git scripting githooks
source share
1 answer

Why not write a post-commit hook (for example) that will look for the post-commit-hooks subdirectory and list and execute all the scripts that are in it?
(the first one that does not start successfully will fail after all attempts after fixing)

If users initialize their Git repo from a predefined template directory , you can make sure that they all receive these special scripts in their new repo.

+3
source share

All Articles