7

I would like to use pre-commit hook in gitlab. I doing everything like in documentation: https://docs.gitlab.com/ce/administration/custom_hooks.html

In custom_hooks directory I've created pre-commit file with folowing content:

#!/bin/bash

exit 1

Hook is never triggered, couse i can commit.

When i do the same with pre-receive hook - everything works good.

If Gitlab doesnt't let to use pre-commit hook?

Robert Grądzki
  • 139
  • 1
  • 2
  • 8
  • 2
    Solved - pre-commit is a client-side hook and should be stored in .git/hooks location on client machine (in my case on Windows). It’s important to note that client-side hooks are not copied when you clone a repository. I will try do everything using server-side hooks. – Robert Grądzki Sep 30 '16 at 08:46

1 Answers1

6

As explained in Customizing Git - Git Hooks, a client-side hook won't be used on the server.

I explained before why it is not possible to include hooks in a clone:

Since GitLab 7.5, you can set custom Git Hooks for server-side hooks.

Git natively supports hooks that are executed on different actions. Examples of server-side git hooks include pre-receive, post-receive, and update

Normally, Git hooks are placed in the repository or project's hooks directory. GitLab creates a symlink from each project's hooks directory to the gitlab-shell hooks directory for ease of maintenance between gitlab-shell upgrades

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250