andkirby / commithook
PHP Commit Hooks
Requires
- php: >=5.5
- chobie/jira-api-restclient: ^2.0@dev
- knplabs/github-api: ~1.4@stable
- rikby/console-helper: ^0.11
- rikby/crypter: ~1.0@stable
- symfony/console: ~3.0@stable
- symfony/filesystem: ~2.5@stable
- symfony/finder: ~2.5@stable
- zendframework/zend-cache: ~2.5@stable
Requires (Dev)
- escapestudios/symfony2-coding-standard: ~2.0@stable
- phpunit/phpunit: ~4.0@stable
- squizlabs/php_codesniffer: 2.*@stable
- symfony/process: ^3.1@stable
Suggests
- squizlabs/php_codesniffer: Suggested v2.* for using code sniffer
- dev-master
- dev-develop / 2.x-dev
- v2.0.0-beta.46
- v2.0.0-beta.45
- v2.0.0-beta.44
- v2.0.0-beta.43
- v2.0.0-beta.42
- v2.0.0-beta.41
- v2.0.0-beta.40
- v2.0.0-beta.39
- v2.0.0-beta.38
- v2.0.0-beta.37
- v2.0.0-beta.36
- v2.0.0-beta.35
- v2.0.0-beta.34
- v2.0.0-beta.33
- v2.0.0-beta.32
- v2.0.0-beta.31
- v2.0.0-beta.30
- v2.0.0-beta.29
- v2.0.0-beta.28
- v2.0.0-beta.27
- v2.0.0-beta.26
- v2.0.0-beta.25
- v2.0.0-beta.20
- v2.0.0-beta.19
- v2.0.0-beta.18
- v2.0.0-beta.15
- v2.0.0-beta.14
- v2.0.0-beta.13
- v2.0.0-beta.12
- v2.0.0-beta.11
- v2.0.0-beta.10
- v2.0.0-beta.8
- v2.0.0-beta.7
- v2.0.0-beta.6
- v2.0.0-beta.5
- v2.0.0-beta.4
- v2.0.0-beta.3
- v2.0.0-beta.2
- v2.0.0-beta.1
- v2.0.0-beta.0
- v2.0.0-beta+2015-10-13
- v1.8.0-p3
- v1.7.0b.2
- v1.7.0b.1
- v1.7.0b
- v1.7.0a
- v1.6.10-alpha.12
- v1.6.10-alpha.11
- v1.6.10-alpha.10
- v1.6.10-alpha.9
- v1.6.10-alpha.8
- v1.6.10-alpha.7
- v1.6.10-alpha.6
- v1.6.10-alpha.5
- v1.6.10-alpha.4
- v1.6.10-alpha.3
- v1.6.10-alpha.2
- v1.6.10-alpha.1
- v1.6.10-alpha
- v1.6.9
- v1.6.8
- v1.6.7
- v1.6.6
- v1.6.5
- v1.6.4
- v1.6.3
- v1.6.1
- v1.6.0
- v1.5.1
- dev-feature/117
- dev-stable
This package is auto-updated.
Last update: 2024-11-20 01:36:56 UTC
README
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).
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)
- PHP example:
$ commithook config --xpath code/interpreter/php d:/s/php-7.0.14/php.exe --project-self
(You may try to use PHP Windows Binaries Downloader (gist))
- PHP example:
- Install extra code validators:
- PHPCS
$ composer global require squizlabs/php_codesniffer:~2.0@stable
- JSHint (original).
- Rubocop installation.
- PHPCS
- (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
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
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
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.