https://github.com/wecodemore/GitPHPHooks
Write your Git Hooks in PHP, organize them on a per-project base and automatically add them.
https://github.com/wecodemore/GitPHPHooks
Last synced: 13 days ago
JSON representation
Write your Git Hooks in PHP, organize them on a per-project base and automatically add them.
- Host: GitHub
- URL: https://github.com/wecodemore/GitPHPHooks
- Owner: wecodemore
- Created: 2014-07-18T16:18:20.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2016-04-05T00:43:01.000Z (about 9 years ago)
- Last Synced: 2025-03-23T07:33:36.351Z (25 days ago)
- Language: PHP
- Size: 19.5 KB
- Stars: 64
- Watchers: 7
- Forks: 7
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-git-hooks - GitPHPHooks - Write your hooks in PHP, manage and organize them on a task and project level. Has an additional Hooks library on GitHub. (Projects)
README
[](https://packagist.org/packages/wcm/git-php-hooks)
[](https://github.com/wecodemore/GitPHPHooks/releases)
[](https://packagist.org/packages/wcm/git-php-hooks)
[](https://packagist.org/packages/wcm/git-php-hooks)
[](https://github.com/wecodemore/GitPHPHooks/stargazers)
# Git PHP Hooks
Write your git hooks in PHP, organize them on a per project base and attach them automatically.
## Git Hooks
> Hooks are little scripts you can place in `$GIT_DIR/hooks` directory to trigger action at certain points.
There're two types of git hooks:
1. pre-push (runs client side)
1. post-push (runs server side)For more info on Git Hooks, please [take a look at the official docs](http://git-scm.com/docs/githooks) - they are quite good.
## How to
It's really easy:
1. Add a folder to your project/repository. The name doesn't matter, as you have to specify
it when triggering `GitPHPHooks`. The name in the following example is `'project-hooks'`. (Hint: Not having a name allows you to customize and organize it as you like. It also allows `git clone`ing into a project specific directory.)
1. Open your `.git/hooks` directory and add a new Git hook file. For example: `pre-commit`
(without file extension).
1. Add a new PHP file to the newly created custom Git hooks folder (again, `'project-hooks'` in the example) that performs the task you want.That's it.
All your Git hooks (inside `.git/hooks`) will have the same contents - only the target folder (`'project-hooks'`) name will (maybe) differ.
```php
#!/usr/bin/env php
We want to run PHPLint before we commitAdd a new file named `pre-commit` in your `.git/hooks` directory. Then add a new directory in the
root folder of your project/repository, named i.e. `project-hooks`. In there, add a new PHP file
named `pre-commit_lint_10.php`. This file will automatically get added to your `pre-commit` hook
where you called the `\GitHooksLoader()` like shown above. It will get added with a priority
of 10. Then just put the following contents in your new file:```php
#!/usr/bin/env php