Git It Right: Innovating Commit Message Validation

Bharat
Deutsche Telekom Digital Labs
3 min readNov 21, 2023
Local Commit Message Validation using git hooks

In software development, keeping code quality high is crucial. A big part of this is having clear and consistent commit messages that provide context. But it’s tough to enforce this when different team members have different habits.

Developers in our team were not using a standard commit message format. This caused issues like not being able to easily track changes, connect commits to tasks, or understand their purpose. We were using the free version of GitLab, which couldn’t enforce commit message rules. So, we needed a custom solution to fix our commit message quality in GitLab.

Solution

To address this issue, we decided to implement commit message validations at both the client and server sides.

On the client side, we chose to leverage Git hooks, specifically the “commit-msg” hook, to validate commit messages right on developer’s local machines before they even committed on local machine. This approach was essential as it could catch issues early in the development process.

git commit lifecycle
Git Commit Validation

However, manually configuring these Git hooks on each developer’s machine can be cumbersome and prone to inconsistencies. Coordinating the installation and configuration process for Git hooks across the team becomes a challenge, especially as the team size grows. Additionally, without automation, enforcing consistent coding standards and performing necessary checks becomes a manual and error-prone task.

After a thorough brainstorming session that explored various options, we opted to create an IntelliJ Idea plugin “Init Script Runner”. This plugin was designed to automatically adjust the commit message hook file on a developer’s local machine whenever they opened a project in IntelliJ.

Init Script Runner Plugin

The Init Script Runner Plugin simplifies the Git hook setup process. It automatically executes custom scripts located in the `.scripts` folder of the project whenever the project is opened in IntelliJ IDEA. This allowed us to seamlessly integrate necessary Git hooks and enforce commit message validations consistently across the team.

Steps to Setup:

  1. Install the Plugin:

To experience the power of the Init Script Runner Plugin, you can download it from the official JetBrains Plugin Repository — Init Script Runner — IntelliJ IDEs Plugin | Marketplace (jetbrains.com)

Or simply search for “Init Script Runner” and click on the installation button to add the plugin to your IntelliJ environment.

2. Create the .scripts folder in each project.

3. Place bash scripts in .scripts folder.

4. Bash scripts should copy the Git Hooks files to <Project Directory>/.git/hooks/ directory.

Setting up Git hooks on the local machines of every developer in a team is crucial for maintaining code quality and collaboration. The Init Script Runner Plugin simplifies this process by automating the execution of custom scripts when projects are opened in IntelliJ. By leveraging this plugin, teams can ensure consistent Git hook configurations, streamline workflows, and enforce coding standards effortlessly. Say goodbye to manual Git hook setup and embrace the efficiency and consistency provided by this powerful IntelliJ plugin, enabling smooth collaboration and improved code quality in your development projects.

Further Reading:

For a deeper understanding of the internal workings(internal_s) and diverse applications of Git hooks, you can explore more in detail in this resource.” — A Comprehensive Guide to Git Hooks: Automate Your Workflow Like a Pro | by Bharat | Jun, 2023 | Medium

--

--