Skip to content

git: Implement a new hooks payload structure

In order to pass information to Git hooks, we need to use environment variables as execution of those hooks is controlled by Git and not by us. As such, we have over time grown a set of variables which our hooks expect to always be present. Unfortunately, the downside is that now we have this environment setup all over the place while it is not obvious which environment variables are expected to be present where. The result is code which is hard to understand which leads to more bugs in our already fragile hook code.

This commit is a first step to fix this by introducing a new variable "GITALY_HOOKS_PAYLOAD" [1]. This variable is going to hold a serialized structure which contains most the parameters required to execute hooks. For now, it only contains information about the binary directory, internal socket as well as the repository. But in future iterations, this will be extended to also contain all of our "GL_" values and possibly other values which are required.

This conversion also fixes an ambiguity in environment variables we have recently introduced. We nowadays run most of our commands with a hook environment which sets up "GITALY_SOCKET" and the likes. But in fact, the gitaly-ssh transport helper we use for fetching from other Gitaly servers requires these variables to point to the remote Gitaly server. As a result, we now have a conflict in intent, which is also going to be solved by the new payload.

Part of #3201 (closed) [1]: https://xkcd.com/927/

Merge request reports

Loading