Since CaptainHook supports Docker as
run-mode for quite a while and since the
run-mode configuration is quite extensible, it took me not much time to connect the dots.
captainhook command for ddev needs to be created, which can be invoked by the Git hooks. For this, create a new file called
captainhook in the
.ddev/commands/web/ directory with the following content:
## Description: Executes CaptainHookPHP Git hook
Since the full path to the CaptainHook CLI script, incl. all parameters is passed via the generated Git Hook scripts, it is enough to execute whatever input is given. The command can now be invoked via
captainhook.json configuration file, the
run-mode needs to be configured like this:
"run-exec": "ddev captainhook",
run-mode needs to be set to docker, the executable command is
ddev captainhook and additionally, the
run-path needs to be defined, otherwise the CaptainHook installer is not properly able to resolve the path to the CLI script.
To install the Git Hooks run the following command on your host or in the web docker container:
This will instruct CaptainHook to generate the Git Hook scripts, which look like this:
ddev captainhook /var/www/html/vendor/bin/captainhook hook:commit-msg "$@"
As you can see, the Git Hook will run the
ddev captainhook command, which we defined earlier, and pass the path to the CaptainHook CLI script as well as the Git hook type.
These are all the steps needed to be able to use CaptainHook in a DDEV environment.