rycus86 / githooks

Githooks: per-repo and global Git hooks with version control
MIT License
380 stars 19 forks source link

.githooks for bare repositories #159

Open mjk-gh opened 3 years ago

mjk-gh commented 3 years ago

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:

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. :)

rycus86 commented 3 years ago

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.

gabyx commented 3 years ago

@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!

gabyx commented 3 years ago

@mjk-gh : See my answer in https://github.com/gabyx/Githooks/issues/24 If this helps you -> Star it ;-)

mjk-gh commented 3 years ago

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 list should 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". :)

mjk-gh commented 3 years ago

@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.