Skip to content

CommitHooks code validation and auto-formatting commit message.

License

Notifications You must be signed in to change notification settings

andkirby/commithook

Repository files navigation

CmHook

CmHook is GIT commit hook the code validator for PHP (Code Sniffer), CSS (base only), JS (JsHint) code and commit message formatter/filler with the issue tracker integration (JIRA, GitHub).

Gitter

The main purpose of this project is

  • checking coding standards before commit (by using PHP CodeSniffer, JSHint, RuboCop, or any lint tool)
  • filling up commit messages automatically to proper format (details)

Supported file types: php, phtml, js, coffee, css, scss, xml, sh, scss, css, json, less, html, htm.

The simplest commit message you could ever make

Target commit message:

Implemented #33: Make smth good now
 - Added my file.

This commit message will be generated automatically, we need to type only commit description:

$ git add myfile.php
$ git commit -m 'Added my file.'

See more details about short commit messages.

Installation

Latest release is v2.0.0-beta.47

Install globally

To get last beta version please define your minimum-stability.

{
  "minimum-stability": "beta",
  "prefer-stable": true
}

Due to reason the package requires one package which still in "dev", please fetch it first:

$ composer global require chobie/jira-api-restclient ^2.0@dev

Now fetch the package:

$ composer global require andkirby/commithook ~2.0@beta

Enable hooks in a project (with predefined configuration)

If a project already have base configuration files all what you need to:

  • define interpreters (PHP for PHPCS, Ruby for Rubocop, NodeJs for JSHint)
  • Install extra code validators:
  • (optional) Perhaps, you have to define binaries for extra code validators in case they are not allow to use globally. (e.g. JSHint, any see how to install any "linter" in this example.)
  • Install GIT hook files
    $ commithook install
    
  • Enable your tracker integration:
    $ commithook tracker:wizard
    

Sample .bashrc

Here is an example of .bashrc file for global using.

Separate installation

If global way doesn't work you may use installation via create-project.

Documentation references

Installation

Initialize configuration wizard
GIT integration: hook files installation

Password tracker update

Password update

Code validation

Ignore validation
Protect code
Enable JsHint validation (Javascript)

Commit message

Commit message format
Ignore commit message validation
Active task in commit message
Auto-explode commit message into the list

Problems

Bugs

Issue bugs list.

Code validators doesn't work with GIT cache

The code validation works with GIT but it doesn't support git cache. It means if you added a file (git add file.php), changed it, and trying to commit (without adding it into GIT cache). In commit, of course, you will get code from cache but validators will validate your real file. (#113)

Minor bugs in short commit message

#92, #91, #32

Tips & tricks

Redundant gaps in code

You may quickly find gaps/trailing spaces in your code by the regular expression:

(\n\s*\n\s*\})|(\n\s*\n\s*\n)|(\{\n\s*\n)| +\n

Just use it in your IDE.

OS environment

Tested on Windows in GIT Bash v2.9.

Feel free to create your faced issue.

About

CommitHooks code validation and auto-formatting commit message.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages