All Projects → m1foley → Fit Commit

m1foley / Fit Commit

Licence: mit
A Git hook to validate your commit messages based on community standards.

Programming Languages

ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to Fit Commit

pre-commit-hooks
git pre-commit hooks
Stars: ✭ 71 (-84.83%)
Mutual labels:  git-hooks
elixir git hooks
🪝 Add git hooks to Elixir projects
Stars: ✭ 98 (-79.06%)
Mutual labels:  git-hooks
Static Review
✋ An extendible framework for version control hooks.
Stars: ✭ 330 (-29.49%)
Mutual labels:  git-hooks
modern-office-git-diff
An experiment in tracking and diffing versions of modern Microsoft Office files in Git.
Stars: ✭ 51 (-89.1%)
Mutual labels:  git-hooks
rusty-hook
git hook manager, geared toward Rust projects
Stars: ✭ 93 (-80.13%)
Mutual labels:  git-hooks
git-conventional-commits
Git Conventional Commits Util to generate Semantic Version and Markdown Change Log and Validate Commit Messag
Stars: ✭ 58 (-87.61%)
Mutual labels:  git-hooks
captain-git-hook
✅ define git hooks as scripts in your package.json
Stars: ✭ 25 (-94.66%)
Mutual labels:  git-hooks
Awesome Git Hooks
😎 A collection of awesome Git Hooks
Stars: ✭ 407 (-13.03%)
Mutual labels:  git-hooks
enforce-git-message
Enforces conventional git commit messages for git repositories
Stars: ✭ 30 (-93.59%)
Mutual labels:  git-hooks
git-semantics
Git hook to ensure semantic commit messages.
Stars: ✭ 42 (-91.03%)
Mutual labels:  git-hooks
husky-elixir
🐶 Git hooks made easy
Stars: ✭ 47 (-89.96%)
Mutual labels:  git-hooks
php-git-hooks
Git hooks for the local repository of the PHP project
Stars: ✭ 20 (-95.73%)
Mutual labels:  git-hooks
modular-git-hooks
A tool for organizing git hooks into directories of modular files.
Stars: ✭ 19 (-95.94%)
Mutual labels:  git-hooks
run-if-changed
Run a command if a file changes via Git hooks
Stars: ✭ 25 (-94.66%)
Mutual labels:  git-hooks
Grumphp
Submitting bugs and feature requests
Stars: ✭ 3,679 (+686.11%)
Mutual labels:  git-hooks
pre-commit-opa
Pre-commit git hooks for Open Policy Agent (OPA) and Rego development
Stars: ✭ 53 (-88.68%)
Mutual labels:  git-hooks
mestral
Simple hook management for Git
Stars: ✭ 55 (-88.25%)
Mutual labels:  git-hooks
Komondor
Git Hooks for Swift projects 🐩
Stars: ✭ 450 (-3.85%)
Mutual labels:  git-hooks
Git Confirm
❓ Git hook to catch placeholders and temporary changes (TODO / @ignore) before you commit them.
Stars: ✭ 356 (-23.93%)
Mutual labels:  git-hooks
elint
A easy way to lint your code
Stars: ✭ 38 (-91.88%)
Mutual labels:  git-hooks

Fit Commit

A Git hook to validate your commit messages based on community standards.

Example

$ git commit
Adding a cool feature
foobar foobar foobar,
foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar

1: Error: Message must use imperative present tense.
2: Error: Second line must be blank.
3: Error: Lines should be <= 72 chars. (76)

Force commit? [y/n/e] ▊

Prerequisites

  • Ruby >= 1.9 (OS X users already have this installed)

Installation

Install the gem:

$ gem install fit-commit

Install the hook in your Git repo:

$ fit-commit install

This creates a .git/hooks/commit-msg script which will automatically check your Git commit messages.

Validations

  • Line Length: All lines must be <= 72 chars (URLs excluded). First line should be <= 50 chars. Second line must be blank.
  • Tense: Message must use imperative present tense: "Fix bug" and not "Fixed bug" or "Fixes bug."
  • Subject Period: Do not end your subject line with a period.
  • Capitalize Subject: Begin all subject lines with a capital letter.
  • Frat House: No offensive content.
  • WIP: Do not commit WIPs to shared branches (disabled by default)

Configuration

Settings are read from these files in increasing precedence: /etc/fit_commit.yml, $HOME/.fit_commit.yml, config/fit_commit.yml, ./.fit_commit.yml.

These are the default settings that can be overridden:

---
Validators/LineLength:
  Enabled: true
  MaxLineLength: 72
  SubjectWarnLength: 50
  AllowLongUrls: true
Validators/Tense:
  Enabled: true
Validators/SubjectPeriod:
  Enabled: true
Validators/CapitalizeSubject:
  Enabled: true
  WarnOnWiplikes: true
Validators/Frathouse:
  Enabled: true
Validators/Wip:
  Enabled: false

The Enabled property accepts multiple formats:

# true/false to enable/disable the validation (branch agnostic)
Validators/Foo:
  Enabled: false
# Array of String or Regex matching each branch it's enabled on
Validators/Bar:
  Enabled:
    - main
    - !ruby/regexp /\Afoo.+bar/

Adding Custom Validators

Create your custom validator as a FitCommit::Validators::Base subclass:

module FitCommit
  module Validators
    class MyCustomValidator < Base
      def validate_line(lineno, text)
        if text =~ /sneak peak/i
          add_error(lineno, "I think you mean 'sneak peek'.")
        end
      end
    end
  end
end

# A validator can also validate the commit message as a whole:
module FitCommit
  module Validators
    class MyCustomValidator < Base
      def validate(lines)
        if lines.none? { |line| line.text =~ /#\d+/ }
          add_warning(lines.last.lineno, "Related issue not referenced.")
        end
      end
    end
  end
end

Require the file and enable the validator in your config:

FitCommit:
  Require:
    - somedir/my_custom_validator.rb
Validators/MyCustomValidator:
  Enabled: true

You can also publish your validator as a gem, and require it that way:

FitCommit:
  Require:
    - my-custom-validator-gem
Validators/MyCustomValidator:
  Enabled: true

If others might find your validator useful, submit it as a Pull Request. If it's not useful for everyone, it can be disabled by default.

FAQ

Can Fit Commit run in all my repos without having to install it each time?

First set your global Git template directory:

$ git config --global init.templatedir '~/.git_template'
$ mkdir -p ~/.git_template/hooks

Now you can copy the hooks you want installed in new repos by default:

# From a repo where Fit Commit is already installed
$ cp .git/hooks/commit-msg ~/.git_template/hooks/commit-msg

To copy your default hooks into existing repos:

$ git init

How can I run this standalone, like part of a CI process?

Fit Commit can be run outside of a Git hook context with a simple shell script:

$ export GIT_BRANCH_NAME=branch_name
$ export COMMIT_MESSAGE_PATH=path/to/message
# Using Bundler
$ bundle exec ruby -e 'require "fit_commit"; FitCommit.run'
# Not using Bundler
$ rbenv exec ruby -rrubygems -e 'require "fit_commit"; FitCommit.run'

It exits with an error code if any errors are present, which will fail a build if it's part of a CI run.

Who decided these rules?

Fit Commit aims to enforce community standards. The two influential guides are:

The Git community has largely (but not completely) coalesced around these standards. Chris Beams and the Pro Git book also provide good summaries on why we have them.

How can I improve Fit Commit?

Fit Commit aims to be useful to everyone. If you can suggest an improvement to make it useful to more people, please open a GitHub Issue or Pull Request. See CONTRIBUTING.md for more info.

Credits

Author: Mike Foley

Inspiration taken from: Tim Pope, Jason Fox, Addam Hardy, pre-commit

Similar projects:

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].