简体   繁体   中英

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

If I...

  • have filesystem access to the server hosting the Git data of a GitLab Community Edition installation
  • ...already have a working pre-commit hook for client-side installation, that blocks commits that fail specific rules (eg C files that have lines ending in whitespace)
  • ...and then copy this pre-commit hook inside a custom_hooks folder under the repository's top-level folder, as described here

...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 (ie under hooks/pre-commit) - and am looking for a quick way to apply the same checking logic server-side.

PS 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.

  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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM