Skip to content

Latest commit

 

History

History
executable file
·
82 lines (53 loc) · 2.3 KB

README.md

File metadata and controls

executable file
·
82 lines (53 loc) · 2.3 KB

Basic git hooks for PHP

Intro

Information about git hooks on the internet is too scattered so I decided to make my own.

IMPORTANT! The hooks are not plug-n-play. You will still need to adjust them to your environment. By default all checks are triggered.

External links:

Requirements

  • *nix flavour
  • php
  • phpunit
  • phpcs
  • phpdoc

Installation

For client-side hooks (pre-commit and post-merge) copy CONFIG file and the corresponding hook file to .git/hooks/ directory on local repository.

For server-side hooks (pre-receive) copy CONFIG file and the corresponding hook file to hooks/ directory on remote repository.

Pre Commit

"This hook is invoked by git commit, and can be bypassed with --no-verify option."

Actions

  • only checks indexed files contents
  • forbid words like var_export, var_dump, print_r in php files
  • enforce a coding standard with PhpCodeSniffer
  • check php syntax with php -l
  • run unit tests with phpunit
  • forbid console.* in js files

Demo:

Demo

Post Merge

"This hook is invoked by git merge, which happens when a git pull is done on a local repository."

Actions

Pre Receive

"This hook is invoked by git-receive-pack on the remote repository, which happens when a git push is done on a local repository."

Actions

  • forbid words like var_export, var_dump, print_r in php files
  • enforce a coding standard with PhpCodeSniffer
  • check php syntax with php -l
  • forbid console.* in js files

Credits