| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
It is exhausting to edit files again and again to have a consistent style. This project provides a Git pre-receive hook to validate pushed commits on the Git server side. The hook avoids all issues by rejecting any commit not matching the rules to get in to the repository in the first place.
The pre-receive hook runs some checks on commits on its own, and searches for programming language specific syntax checkers on the PATH of the server to check changed files with them. The process is pretty fast, because only the added and modified files on the pushed commits are passed to the syntax checkers, also in parallel. It wouldn't slow you down unless your commits are touching hundreds of files.
It is possible to install the tool with pip:
pip install igcommit
Link the script to hooks/pre-receive on you Git repositories on your Git server:
ln -s igcommit-receive /home/git/repositories/myproject.git/hooks/pre-receive
Here is an example problem output:
=== CheckDuplicateCommitSummaries on CommitList === ERROR: summary "Add nagios check for early expiration of licenses" duplicated 2 times === CheckCommitSummary on 31d0f6b === WARNING: summary longer than 72 characters === CheckCommitSummary on 6bded65 === WARNING: past tense used on summary === CheckCommand "flake8" on src/check_multiple.py at 6bded65 === INFO: line 10 col 5: E225 missing whitespace around operator INFO: line 17 col 80: E501 line too long (122 > 79 characters) INFO: line 17 col 85: E203 whitespace before ',' === CheckCommitMessage on 6fdbc00 === WARNING: line 7 is longer than 80 WARNING: line 9 is longer than 80
The script itself is currently configuration free. Though, some of the syntax checkers called by the script uses or requires configurations. Those configuration files has to be on the top level of the Git repository.
| Syntax Checker | Configuration File | |
|---|---|---|
| coffeelint | coffeelint.json, or package.json | optional |
| csslint | .csslintrc | optional |
| eslint | eslint.(js|yaml|yml|json), or package.json | required |
| flake8 | .flake8, setup.cfg, or tox.ini | optional |
| htmlhint | .htmlhintrc | optional |
| jscs | .jscsrc, .jscs.json, or package.json | required |
| jshint | .jshintrc, or package.json | optional |
| phpcs | phpcs.xml, or phpcs.xml.dist | optional |
| puppet-lint | .puppet-lint.rc | optional |
| pycodestyle | setup.cfg, or tox.ini | optional |
| rubocop | .rubocop.yml | optional |
A continuous integration server can run such checks with the many other things it is doing. Moving this job from it has many benefits:
Even though, pre-receive hook gives later feedback than pre-commit hook, it has many advantages over it:
The script has no dependencies on Python 3.4 or above. The script executes the validation commands using the shell. The necessary ones for checked repositories need to be installed separately. See the complete list of commands on the config.py. The commands which are not available on the PATH is not going to be used.
I found it useful to check what the script would have complained if it had been active on different Git repositories. You can run a command like this to test this inside a Git repository against last 50 commits:
git log --reverse --oneline HEAD~50..HEAD |
sed 's:\([^ ]*\) .*:\1 \1 refs/heads/master:' |
python ../igcommit/igcommit-receive
The script is released under the MIT License. The MIT License is registered with and approved by the Open Source Initiative [1].
| [1] | https://opensource.org/licenses/MIT |
| Back | FazBrowse Home | New Git URL |