In this page

Overview

This page is about implementing the Commit Policy Plugin with the Git version control system and GitLab CE/EE. If you use Git alone (i.e. without GitLab CE/EE), please see the Git page instead.

Working with GitLab CE/EE commit policies

GitLab CE/EE builds on the top of the Git version control system, extending that with repository, user and permission management capabilities, workflows and other high level functionality. Therefore, everything written in the Git page also applies when using GitLab CE/EE.

From the Commit Policy Plugin's angle, the only difference between using Git alone and Git with GitLab CE/EE is the set-up steps of the commit hook. This is detailed in the next section, but this is only relevant to you if you are an administrator of the GitLab CE/EE. If you are a developer (making commits and pushing those to the GitLab CE/EE), you can use your Git client regardless if the server runs Git alone or Git with GitLab CE/EE.

In any case, make sure you read the Git page. It explains fixing rejected commits, working with Git features (branching, merging, rebasing, tagging, cherry-picking) and helps to resolve common problems.

Installing GitLab commit hooks

First off, read the custom hooks page in the GitLab documentation, to learn how to install hook scripts to GitLab CE/EE server managed Git repositories.

To install the hook scripts for the Commit Policy Plugin, just follow the web based Hook Script Generator wizard until the step 1: Unpack the ZIP file to the location where Git expects it. Then ignore the wizard's hook script installation instructions, because GitLab is using slightly different directory structure.

Instead, follow the instructions below:

  1. Extract the hook script package to a directory named custom_hooks inside your Git repository. If custom_hooks does not exist yet, create it. The repository path should look like this: /var/opt/gitlab/git-data/repositories/<group>/<project>.git
  2. Change the owner of the custom_hooks directory and all files in it to git:git:
    chown -R git:git /var/opt/gitlab/git-data/repositories/<group>/<project>.git/custom_hooks
    
  3. Open jcp_git_common.py in a plain text editor, and modify the method called started_manually() at the end of the file to this:
    def started_manually():
    	is_gitlab = "gitlab" in sys.argv[0] and "/custom_hooks/" in sys.argv[0]
    	return not sys.argv[0].startswith("hooks") and not is_gitlab and not sys.argv[0].startswith(".git")
    

After this, you can continue with the wizard from the 2: Set permissions and run a diagnostic test step.

An easier way to generate and install GitLab hooks

Albeit this solution works perfectly, we plan to make the installation process more convenient by offering GitLab as a separate option when selecting the VCS in the Hook Script Generator wizard. If you are interested in that feature, please send a short email to info at midori-global.com so that we know that this is important for you.

Questions?

Ask us any time.