ttsiodras
ttsiodras

Reputation: 11258

Do server-side pre-commit hooks work in GitLab community edition?

If I...

...will I then be able to block people from pushing commits that violate the checks made by the hook?

 $ cd /var/opt/gitlab/git-data/repositories/someone/somerepo.git/
 $ mkdir custom_hooks
 $ sudo chown git.git custom_hooks
 $ cp /path/to/some/pre-commit-hook custom_hooks/pre-commit
 $ sudo chown git.git custom_hooks/pre-commit
 $ sudo chmod 755 custom_hooks/pre-commit

The hook in question already works client-side - but I am asking here because I am not sure of two things:

  1. Is this functionality supported in the Community Edition of GitLab? The linked article above claims "CORE ONLY" in bold, which I am guessing means this doesn't work for the Community Edition?

  2. Can a pre-commit hook function as-is on the server-side? Or do I need to adapt to using a different hook instead (pre-receive?) If so, an example adaptation would help a lot.

To make sure I am not creating another instance of the XY problem: what I am asking for is a simple example of how to setup server-side GitLab Community Edition commit "filters" that are run when "git push" is executed from the committers. I already have a working version of such a filter for client-side Git hook-ing (i.e. under hooks/pre-commit) - and am looking for a quick way to apply the same checking logic server-side.

P.S. Already tried the naive thing, of copying the hook as-is under the "hooks" folder on the server-side: no change - commits go through without any checks.

Upvotes: 1

Views: 3722

Answers (1)

Joao  Vitorino
Joao Vitorino

Reputation: 3266

  1. Is this functionality supported in the Community Edition of GitLab? The linked article above claims "CORE ONLY" in bold, which I am guessing means this doesn't work for the Community Edition?

Yes. You can add custom-hook script per repository or a global script for all repositories in Gitlab CE

  1. Can a pre-commit hook function as-is on the server-side? Or do I need to adapt to using a different hook instead (pre-receive?) If so, an example adaptation would help a lot

A pre-commit hook will run before a commit, in server-side, this doesn't make sense. You need to transform your pre-commit into a pre-receive, pre-push, post-receive or update script hook. I believe, in your case, you need a pre-receive hook to check the commit before accept it in gitlab. Here the documentation of all scripts hook types.

Upvotes: 2

Related Questions