NAME

git-lint - lint git commits and messages

SYNOPSIS

git-lint [--check commit] [--check message <message_file>]
         [--profile <name>]
         [--version] [--help]

DESCRIPTION

git-lint is the commandline interface to Git::Lint, a pluggable framework for linting git commits and messages.

OPTIONS

--check

Run either check type commit or message.

If check type is message, git-lint expects the file path of the commit message to check as an unnamed option.

git-lint --check message message_file
--profile

Run a specific profile of check modules.

Defaults to the 'default' profile.

--version

Print the version.

--help

Print the help menu.

CHECK MODES

git-lint has 2 check modes, commit and message.

commit

The commit check mode checks each line of the commit diff for issues defined in the commit check modules.

message

The message check mode checks the commit message for issues defined in the message check modules.

CONFIGURATION

Configuration is done through git config files (~/.gitconfig or /repo/.git/config).

Only one profile, default, is defined internally. default contains all check modules by default.

The default profile can be overridden through git config files (~/.gitconfig or /repo/.git/config).

To set the default profile to only run the Whitespace commit check:

[lint "profiles.commit"]
    default = Whitespace

Or set the default profile to Whitespace and the fictional commit check, Flipdoozler:

[lint "profiles.commit"]
    default = Whitespace, Flipdoozler

Additional profiles can be added with a new name and list of checks to run.

[lint "profiles.commit"]
    default = Whitespace, Flipdoozler
    hardcore = Other, Module, Names

Message check profiles can also be defined.

[lint "profiles.message"]
    # override the default profile to only contain SummaryLength, SummaryEndingPeriod, and BlankLineAfterSummary
    default = SummaryLength, SummaryEndingPeriod, BlankLineAfterSummary
    # create a summary profile with specific modules
    summary = SummaryEndingPeriod, SummaryLength

An example configuration is provided in the examples directory of this project.

Configuration is required. If no configuration exists, an error will be printed to STDERR, but the action allowed to complete.

blaine@base ~/git/test (master *) $ git add test
blaine@base ~/git/test (master +) $ git commit
git-lint: [error] configuration setup is required. see the documentation for instructions.
[master 894b6d0] test
 1 file changed, 1 insertion(+), 1 deletion(-)
blaine@base ~/git/test (master) $

ADDING NEW CHECK MODULES

git-lint can be configured to load check modules from a local directory using the localdir configuration setting.

To load modules from a local directory, add the lint config setting, with localdir key and directory location to the git config file.

[lint "config"]
    localdir = /home/blaine/tmp/git-lint/lib

In this example, we're adding a new commit check, Flipdoozler. Create the local directory and path for the new module.

$ mkdir -p /home/blaine/tmp/git-lint/lib/Git/Lint/Check/Commit

Then add the new check module.

$ vi /home/blaine/tmp/git-lint/lib/Git/Lint/Check/Commit/Flipdoozler.pm
package Git::Lint::Check::Commit::Flipdoozler;
...

Update the commit check profile to use the new module.

[lint "profiles.commit"]
    default = Whitespace, IndentTabs, MixedIndentTabsSpaces, Flipdoozler

git-lint will now warn for the check contained in Flipdoozler.

blaine@base ~/git/test (master +) $ git commit
git-lint: [commit] test - Flipdoozler (line 18)
blaine@base ~/git/test (master +) $

ENABLING CHECKS FOR REPOS

To enable as a pre-commit hook, copy the pre-commit script from the example/hooks directory into the .git/hooks directory of the repo you want to check.

Once copied, update the path and options to match your path and preferred profile.

To enable as a commit-msg hook, copy the commit-msg script from the example/hooks directory into the .git/hooks directory of the repo you want to check.

COPYRIGHT AND LICENSE

Copyright (c) 2022 Blaine Motsinger under the MIT license.

AUTHOR

Blaine Motsinger blaine@renderorange.com