Unable to set commit-msg hook on GitLab EE

I am trying to set a 'commit-msg' hook so that I can fail any commits that meet a certain criteria. However, it doesn't seem to run.

I have created the following commit-msg file which is intended to fail straight away so I can test that it's working:

#!/bin/bash

echo "Testing git hooks..."
exit 1

I made this file executable and owned by git. I named the file 'commit-msg' without an extension and I placed the file in this directory:

/var/opt/gitlab/git-data/repositories/{group}/{project}.git/hooks

But it does not run. I then moved it to a new directory:

/var/opt/gitlab/git-data/repositories/{group}/{project}.git/custom_hooks/

as per this documentation but it still does not run.

I am aware that I can set this locally in .git/hooks but I want to set this on a server level so all future users will have them.

Is there no way to do this?

If I do have to place it in .git/hooks locally, would any new users also have to place the file in their hooks directory as well?

EDIT: I have tested placing the exact same file within my .git/hooks/ directory within the repo and it works as expected but I'd rather not tell every user that they have to do this so a server level implementation is required

Edited Apr 12, 2019 by Shane
Assignee Loading
Time tracking Loading