In this page

Overview

This page is about implementing Better Commit Policy 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 guide 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 guide also applies when using GitLab CE/EE.

In the Better Commit Policy app's context, the only difference between using Git alone and Git with GitLab CE/EE is how you set up the commit hooks. 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 GitLab CE/EE), you can use your Git client exactly the same way regardless if the server runs Git alone or Git with GitLab CE/EE.

In any case, make absolutely sure you read the Git guide. 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 Better Commit Policy, 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.