There is allegedly a way to completely block merges from a source branch in Git, as illustrated here.
I attempt to enable this possibility in a GitLab repository. However, the documentation for GitLab hooks is quite scarce. After unsuccessfully getting the logs (There are no logs for GitLab hooks anywhere in the Gitaly component, as I am deploying it through Kubernetes. Perhaps this can be modified, but this is currently not documented), I started piping the output into files as a mean to have some logs available.
This is the "logging" pre-receive
hook I created under the custom_hooks
folder:
#!/bin/bash
printenv > env.txt
echo "$@" > args.txt
Yet, the context available to the hook seems fairly limited. The environment doesn't provide any information about branches, not even commits. And there are no arguments appended to the call of this script (unlinke in git hooks), it seems.
The final goal I am pursuing is to block a source branch main
from merging into a target branch that follows the regular expression ^release.*
, in order to avoid merging untested features into production (this is our Git-Flow implementation). This policy should be applied regardless of the permissions given to any user.