Mikko Koivunalho
and 1 contributors


Git::MoreHooks::CheckIndent - Check committed files for problems with indentation.


version 0.005


Use package via Git::Hooks interface (git config file).


This plugin allows user to enforce policies on the committed files. It can define allowed indentation characters (space/tab/both), tab width (1, 2, 3, 4, [..] characters) and on which files or file types to apply which rules.


Package Git::MoreHooks is currently being developed so changes in the existing hooks are possible.


To enable CheckIndent plugin, you need to add it to the githooks.plugin configuration option:

    git config --add githooks.plugin CheckIndent

Git::Hooks::CheckIndent plugin hooks itself to the hooks below:

  • pre-commit

    This hook is invoked during the commit.

  • update

    This hook is invoked multiple times in the remote repository during git push, once per branch being updated.

  • pre-receive

    This hook is invoked once in the remote repository during git push.

  • ref-update

    This hook is invoked when a push request is received by Gerrit Code Review.

  • patchset-created

    This hook is invoked when a push request is received by Gerrit Code Review for a virtual branch (refs/for/*).

  • draft-published

    The draft-published hook is executed when the user publishes a draft change, making it visible to other users.


This plugin is configured by the following git options.

githooks.checkindent.file REGEXP PARAMETERS

A regular expressions matches against the file name. If config has several file items they are used in their order of appearance until a match is found. When a match is found, the parameters are applied to check the file.

Parameters are indent-char (allowed values: space, tab, both) and indent-size (allowed content: an integer number).

    file = ^proj1/old/.* indent-char:both indent-size:2
    file = \.(c|h|cpp|hpp)$ indent-char:tab
    file = \.py$ indent-char:space indent-size:4

N.B. The file name is a regular expression which will be matched against the whole path of the file. The file name is not a File::Glob pattern (like Git::Hooks::CheckFile uses).

githooks.checkindent.exception REGEXP REGEXP

Sometimes we have to make exceptions. After finding the faulty lines ever line is matched against the exceptions. If a match is found, then error is not generated.

The first regular expression is matched against the name of the current file. The second is matched against the row on which an error was found.


This module exports the following routines that can be used directly without using all of Git::Hooks infrastructure.

check_commit_at_client GIT

This is the routine used to implement the pre-commit hook. It needs a Git::More object.

check_commit_at_server GIT, COMMIT

This is the routine used to implement the pre-commit hook. It needs a Git::More object and a commit hash from Git::More::get_commit().

check_affected_refs GIT

This is the routing used to implement the update and the pre-receive hooks. It needs a Git::More object.

check_patchset GIT, HASH

This is the routine used to implement the patchset-created Gerrit hook. It needs a Git::More object and the hash containing the arguments passed to the hook by Gerrit.


Thanks go to Gustavo Leite de Mendonça Chaves for his Git::Hooks package.



'Mikko Koivunalho <mikko.koivunalho@iki.fi>'


This software is copyright (c) 2015 by Mikko Koivunalho.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.