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
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.
The global git config is simply a text file, so it can be edited with whatever text editor you choose. Open, edit global git config, save and close, and the changes will take effect the next time you issue a git command. It's that easy.
The git config command is a convenience function that is used to set Git configuration values on a global or local project level. These configuration levels correspond to . gitconfig text files. Executing git config will modify a configuration text file.
git/hooks directory isn't cloned with the rest of your project, nor is it under version control. A simple solution to both of these problems is to store your hooks in the actual project directory (above the . git directory). This lets you edit them like any other version-controlled file.
No, there isn't any clone hook.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With