hooks: Fix inadvertent execution of hooks
When we set up hooks via configureHooks()
, then we tell git where to
find our git hooks via core.hooksPath
. This allows it to find hooks
and execute them in case any hook needs to run in the context of the
current git command.
"Any" is the important part here, though: even if we want to only
execute e.g. the reference-transaction hook, any other hook would also
get executed if we call configureHooks()
. This is unexpected any may
even be dangerous in some situations given that we now run unexpected
hooks with a potentially wrong setup. It would be fatal if we
accidentally started to execute the pre-receive or post-receive hooks i
we didn't intend to, as they do all kinds of things like triggering CI,
access checks and so on.
This MR thus introduces a new bitfield of requested hooks to the hooks payload: any callsite which configures hooks is expected to say exactly which kinds of hooks it wants to run. For any given hook that gitaly-hooks is then about to execute, it will first check whether the corresponding bit in that bitfield is set -- if not, it'll simply skip execution and return successfully as if the hook didn't exist in the first place.