.githooks for bare repositories
I have to admit I do not fully understand how githooks on the server are supposed to work.
After installation of githooks on the server with
sh -c "$(curl -fsSL https://raw.githubusercontent.com/rycus86/githooks/master/install.sh)" -- --only-server-hooks
and automatic or manual installation of githooks in all repositories on the server, I see that each repository's hook directory contains the appropriate template hooks.
Question is: How do I use these hooks?
I created a hook/.githooks/pre-receive hook script in one of the bare repositories on the server, similar to a script in the .githooks directory of a work tree in a user's local (obviously non-bare) repository, but it did not get called upon a user's "git push".
My use case is that for each repository on the server, I want the individual choice of running multiple server-side hooks each time a user does a "git push". These hooks should enforce various policies (some of them different for each repository) without a user having a chance of getting around them (e.g. by manipulating them in a local repository's .githooks directory). So my requirements are:
- [x] The server-side hooks should reside only on the server (which should already work, as the server-side bare-repo
hooksdirectory will never get transferred to a user's local repository). - [x] The server-side hooks should be specific for a repository. I have no idea where to put my hook scripts, maybe I overlooked something in the documentation.
- [x] Optionally, for specified repositories, there should be centrally stored hook scripts. This is probably already possible via "shared hooks" (not yet tested, because I do not know where to put the actual hook scripts or a
.sharedfile). - [x] There should be the possibility for multiple hook scripts for each event, just like with
.githooksin a local repository.
If githooks is not "the right tool for the job", please let me know, but now that I got your wonderful hammer, every git problem looks like a nail. :-}
Also let me know if I missed the whole thing in the documentation by pointing me to the right location and sending me a cone of shame. :)
I have to admit I do not fully understand how githooks on the server are supposed to work.
Same here to be honest, @gabyx implemented that part, so he may be able to give you more details on how are these supposed to be used.
From https://github.com/rycus86/githooks#setup-for-bare-repositories I see that those hooks need to be accepted and trusted on the server to avoid the user prompt for running them, have you done that? I believe git hooks list should print out the recognized hooks and what state they are in, have a look at that to see if everything is order.
@mjk-gh :
wonderful hammer
😂
Ok to be honest git hooks stuff is not the easiest, it needs a thorough understanding of the underlying git logic an setup sadly. However I have all points above already solved. I ll explain later!
@mjk-gh : See my answer in https://github.com/gabyx/Githooks/issues/24 If this helps you -> Star it ;-)
I have to admit I do not fully understand how githooks on the server are supposed to work.
Same here to be honest, @gabyx implemented that part, so he may be able to give you more details on how are these supposed to be used.
From https://github.com/rycus86/githooks#setup-for-bare-repositories I see that those hooks need to be accepted and trusted on the server to avoid the user prompt for running them, have you done that? D'oh! m)
I totally overlooked that part of the documentation, mea culpa!
I believe
git hooks listshould print out the recognized hooks and what state they are in, have a look at that to see if everything is order.
Good idea, thanks! This would have shown me that the hook /is/ recognized, albeit in a location that is probably not intended (maybe a bug?):
/test/3.git # git hooks list
/test/3.git # cd hooks/ # this dir contains my .githooks dir
/test/3.git/hooks # git hooks list
> pre-receive
- pre-receive (file / pending / new)
/test/3.git #
It also would have given me a hint about the "trust issue". :)
@gabyx:
@mjk-gh : See my answer in gabyx/Githooks#24 If this helps you -> Star it ;-)
Done! Uhm ... more or less ... no stars here, so I ... "fingered" it? ;-}
"Thumbed it up"? Someone help me, seriously.