Git 中文文档 Git 中文文档
指南
GitHub (opens new window)
指南
GitHub (opens new window)
  • 起步

    • 1.1 关于版本控制
    • 1.2 git 简史
    • 1.3 git 是什么
    • 1.4 命令行
    • 1.5 安装 git
    • 1.6 初次运行git前的配置
    • 1.7 获取帮助
    • 1.8 起步 - 总结
  • git 基础

  • git 分支

  • 服务器上的 git

  • 分布式 git

  • github

  • git 工具

  • 自定义 git

  • git 与其他系统

  • git 内部原理

Build Status

CaptainHook


CaptainHookis an easy to use and very flexible git hook library for php developers. It enables you to configure your git hook actions in a simple json file.

You can use CaptainHookto validate or prepare your commit messages, ensure code quality or run unit tests before you commit or push changes to git. You can automatically clear local caches or install the latest composer dependencies after pulling the latest changes.

CaptainHookmakes it easy to share hooks within your team and even can make sure that everybody in your team activates the hooks locally.

You can run cli commands, use some built in validators, or write your own PHP classes that get executed by CaptainHook. For more information have a look at the documentation.

Installation


Install the CaptainHookPHAR using Phive or download the PHAR from the github release page.

  1. ``` shell
  2. phive install captainhook
  3. ```

Or use Composerto install CaptainHook.

  1. ``` shell
  2. composer require --dev captainhook/captainhook
  3. ```

Setup


After installing CaptainHook you can use the captainhookexecutable to create a configuration.

  1. ``` shell
  2. vendor/bin/captainhook configure
  3. ```

Now there should be a captainhook.jsonconfiguration file.

If you are not using the composer-plugin yet you have to activate the hooks manually by installing them to your local .git repository. To do so just run the following captainhookcommand.

  1. ``` shell
  2. vendor/bin/captainhook install
  3. ```

Have a look at this short installation video.

If you want to make sure your whole team uses the same hooks and you want to make sure everybody has the hooks installed you can use the CaptainHookcomposer-plugin as an addition.

  1. ``` shell
  2. composer require --dev captainhook/plugin-composer
  3. ```

The plugin will make sure that the hooks get activated after every composer install or update. If you don't like the extra dependency just add the following scripts command to your composer.json file instead.

  1. ``` json
  2. {
  3.   "scripts": {
  4.     "post-autoload-dump": "vendor/bin/captainhook install -f -s"
  5.   }
  6. }
  7. ```

Configuration


Here's an example captainhook.jsonconfiguration file.

  1. ``` json
  2. {
  3.   "commit-msg": {
  4.     "enabled": true,
  5.     "actions": [
  6.       {
  7.         "action": "\\CaptainHook\\App\\Hook\\Message\\Action\\Beams",
  8.         "options": []
  9.       }
  10.     ]
  11.   },
  12.   "pre-commit": {
  13.     "enabled": true,
  14.     "actions": [
  15.       {
  16.         "action": "phpunit"
  17.       },
  18.       {
  19.         "action": "phpcs --standard=psr2 src"
  20.       }
  21.     ]
  22.   },
  23.   "pre-push": {
  24.     "enabled": false,
  25.     "actions": []
  26.   }
  27. }
  28. ```

Contributing


So you'd like to contribute to the CaptainHook library? Excellent! Thank you very much. I can absolutely use your help.

Have a look at the contribution guidelines.
Last Updated: 2023-09-03 19:17:54