Package: hooks4git
hooks4gitA fully configurable and extensible language-agnostic Hook Management System for GITAuto checks your code before you ship it. Works with any programmning language. If not, let me know.AvailabilityProduction version is available fromPypi, and development branch is also published by Travis-CI toPypi TestServer. Both can be downloaded and installed via the pip command.More information on Git HooksHere. There is lots of quick information, and as well other githooks management approaches.Getting startedThese instructions will show you how to install and use the application.Supported OSsSupported OSs are Linux, MAC and Windows. However, I was not able to make it workcmd.exe(like if cmd.exe even works...). If you are using Windows, use it inside GitBash.DO NOT, I repeat, do not use it oncmd.exe.Installationpipinstallhooks4git--userDepending on your setup, you might want to usepip3instead ofpip. Sometimes, during execution, Python2.7 complains about not finding moduleconfigparser. Using Python3x this doesn't happen.Please, keep in mind that--userfolder might not be on your PATH environment var. Usually you can find it under~/.local/bin. If you fix your$PATHnow, it will be automatically fixed for any other python tool you might eventually install inside your user context.Then, a script calledhooks4gitwill be available all the time, to hook any project you are currently in. By running with the--initargument, hooks will be applied (i.e replace all your sample hook files).Please note you need to manually keep upgrading your system tools, like you do for other tools, like pip itself.Built-in ScriptsThose are currently built-in scripts, some implemented, some planned:check_branch_name: Written in bash, receives a regex as parameter to match your branch name.get_staged_files: Written in Python, will fix Issue#21 ... perhaps. It is still under testing.print_leftovers: Planned, to find print statements. A few can be legit, so a little planning is required here.If you want to use, just follow the exemple on the default .ini file, on sub-section 'checkbranch'. This is the way to trigger built-in scripts, prefixing them with 'h4g/'. Make sure you wrap parameters properly with double quotes.What else do you hate people often push to the repo? Have an idea? Open an issue and let's talk about it. Those IDE .ini files? Yeah, I hate that too.CLI UsageAfter installation, your repo needs to be hooked for all events. Prior version used YAML for configuration management, but that caused PyYAML to be a dependency, and things went a little wrong when running it as a tool. So I choose .ini files over .json files (both have Python native parsers) because it looked less ugly.Inside your git repository, just type:hooks4git--initAnd get all your regular non-sense-hard-to-use-and-hard-to-maintain-and-hard-to-share hook scripts updated.Then, you just need to open.hooks4git.inifile on the root of your project and configure it the way you want.This first example section is meant for Python, but you can use any tool you want, at any given git hook event.Example section for pre-commit, for Python:[scripts]flake8=flake8--max-line-length=119--exclude.git,build,dist,.env,.venvnosetests=nosetests--with-coverage[hooks.pre-commit.scripts]check=flake8It also could be for NodeJS:[scripts]eslint=eslint-fcheckstyleindex.js>checkstyle-result.xmljshint=jshint*.js[hooks.pre-commit.scripts]check_a=eslintcheck_b=jslintNote: All scripts you add here need to be available on your PATH for execution. So you need to make all of them depedencies on your current project, no matter the language it is written with. Per default, the available hooks are onlyechocommands, which will always pass!CI UsageWhen running inside CI, if you manage to havehooks4gitpackage available, you can force trigger a hook this way:hooks4git-t<hook>--ciThis will run the very same set of scrips you ran on your development workstation prior to the commit. Please note that<hook>is any valid entry on.hooks4git.inifile, not only necessarily a git-hook. See below about "Custom Hooks".ColorsThe--ciparameter tells hooks4git to not print in nice colors, just plain strings. But first check if your CI output handle colors or not. For instance, Bitbucket Pipelines handle it nicely, while Jenkins doesn't."Custom Hooks"Hooks have those static names because they are automatically triggered by GIT. However, you can create others inside.hooks4git.inifile. And you can trigger them using the-tparameter.So, if you likecheck_branch_namefeature, you might think running it inside CI wouldn't be a great idea. How to solve it?[hooks.ci-develop.scripts]check=flake8tests=tests_with_reportAs said, there is no "ci-develop" git hook. But due to internalhooks4gitmechanics, using-tflag,hooks4gitwill try to find and run that configuration.So, it would be a matter of adding this to your CI script:-pipinstallhooks4git
-hooks4git-tci-developAnd since you were using flake8 and tests already on your commit and push hooks, you guarantee to run the same tools with the same parameters on CI, with a nice output, colored or not.Disclaimer: This feature was never intended to exist, and happened to work by accident. Since it is kind of cool and doesn't break the law, I decided to document it.OutputHere is a sample output for a Python configuration, with Flake8 (black and white... it has actually a full colored output if --ci parameter is not issued):———————————————————————————————————————————————————————————————————————————————
hooks4gitv0.4.x::Pre-Commit::hooktriggered
———————————————————————————————————————————————————————————————————————————————
STEP|$flake8--max-line-length=119--exclude.git,__pycache__,build,dist
OUT|None
PASS|'flake8'stepexecutedsuccessfully
———————————————————————————————————————————————————————————————————————————————
STEPS|1wereexecuted
TIME|Executiontook0:00:00.684762
PASS|Allgreen!Good!
———————————————————————————————————————————————————————————————————————————————ContributeIf you are willing to code something on this project, it is quite simple. You first need to fork it directly on GitHub, so you can get a copy on your computer that you can push to. Therefore, you would be able to open a Pull Request to the original repository.>gitclonegit@github.com:<super_cool_developer>/hooks4git.git
>cdhooks4git
>pipenvinstall--dev
>pipuninstallhooks4git# just in case, it may fail>pipinstall-e.--user
>hooks4git--init# OF COURSE!!!>gitcheckout-bfeature/super_cool_featureThe above will install hooks4git linked to the folder you cloned the repository to, instead of the module you normally download from Pypi. This way, every change you make on the source code will affect your environment, makeing it easy to use. Of course there are several other ways, like using virtualenv, for instance. That was only a suggestion and affects all repos you have. This is the way I usually test develop versions for a few days prior to a release.LicenseThis project is licensed under MIT license. See theLICENSEfile for detailsAuthorsSee list ofcontributorswho participated in this project.CreditsMarco LovatoCollins Abitekaniza(where I forked from)Change Log0.4.xMajor rework on classes and dependencies usageAdded more testsFixed Issue#57 - Subprocess Call ErrorFixed Issue#54 - Pipenv usageFixed Issue#47 - Colorama usage0.3.xMajor rework on how strings are printed outAdded --ci parameter, so no color will be printed out (Idea fromFernando Espíndola)Auto create hooks folder (inside .git) if it is missing (Idea fromÉdouard Lopez)0.2.xSupport for Windows with GitBashAdded docker scripts for quick clean machine testing environmentBetter exception handling when user configures duplicate sections by mistakeFIXED: Changed default max line length example to 119 instead of 120Replaced copying code to .git/hooks with a safe bash callerReplaced '_' folder (or 'scripts' folder) with 'h4g' folder for internal scriptsFIXED: Script order inside a hook definition was randomStandard Error Output was not being handled and printed accordingly0.1.xInitial release