Skip to content

ReekenX/git-hooks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 

Repository files navigation

GIT hooks

Common GIT hooks for better quality assurance for your projects.

Installing

Two couple of ways to do it.

(1) You can put all scripts to /usr/share/git-core/templates/ and then it will be available for new repos only. For older repos you will need to do git init. Problem with that is that after hooks update git init won't work for existing repos, because git does not override files anymore.

So I suggest poor-man install script defined below.

(2) Poor man install script you can run whatever you want to update git hooks for all your repos:

for folder in $(find ~/Work -maxdepth 3 -type d -name .git); do cp {commit-msg,pre-commit,prepare-commit-msg} $folder/hooks/; chmod +x $folder/hooks/{commit-msg,pre-commit,prepare-commit-msg}; done;

This inline script scans for all repos inside ~/Work folder (this is where you keep your code, right?) and for performance reasons it scans only 3 levels inside every folder.

The rest of the part is copying script to every git repo you have and makes it executable.

(3) Automatic install script - ask for it in the issues tracker. If there will be a need for that - I think I can make it quickly.

prepare-commit-msg hook

This hook is used to construct commit message for author.

If your branch contains some number, like feature/5001 or feat-9001 then your commit message will start with ticket number #5001 or #9001.

It will notify you about ticket number requirement, if you have following in your GIT settings:

[hooks]
    ticketnumbercheck = on

It will show your branch.

It will show short summary of files which are changed.

pre-commit hook

This hook is called before commit message construction and it checks for common mistakes of the projects.

For PHP files it will check syntax error of the file.

For PHP files it will check for newly introduced PSR issues.

For other languages (Python, Ruby, PHP, JavaScript, Mysql) it will check common dangerous words. I still adding other languages there to make it better and might rewrite it a bit to make module support. Feel free to fork this repo and adding stuff!

commit-msg

This hook is called after commit message is saved.

It checks first line to contain ticket number (format: #12345 SOME TEXT). It will be enabled by default, but you can always control it using git config hooks.ticketnumbercheck [on | off].

References

For PHP projects I had similar repo: https://github.com/ReekenX/phpcheck-git

Don't use it! Use this one. It contains:

  • Easier and maintain code.
  • More checks.
  • Easy ability to add new checks.

Bugs

This project has no bugs.

But feel free to file any request or discuss something by creating a new issue: https://github.com/ReekenX/phpcheck-git/issues/new

I normally respond in less than a day. Or just e-mail me (see my profile for e-mail).

About

Common GIT hooks for better quality assurance for your projects.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages