captainhookphp / captainhook

CaptainHook is a very flexible git hook manager for software developers that makes sharing git hooks with your team a breeze.
http://captainhook.info
MIT License
996 stars 86 forks source link

WSL support #241

Closed chriskapp closed 5 months ago

chriskapp commented 6 months ago

Hi, thanks for this project, this is a first draft regarding issue https://github.com/captainhookphp/captainhook/issues/156 which adds native WSL support. Basically it adds a new WSL run mode which only adds wsl.exe to the Shell command, which allows to run the command inside WSL.

sebastianfeldmann commented 6 months ago

Currently I have no way of testing if this works, since I do not have access to a Windows system, so I would have to take your word for it :)

The examples I found were using wsl command... instead of wsl.exe command ... but I think both should work.

The thing I'm a bit confused about is that you still generate a shell script. Does that work even if the git operation is triggered through Windows. You would need at least the git bash to make that work right?

chriskapp commented 6 months ago

Hi @sebastianfeldmann, yes indeed, since the hooks are executed through the git bash, but the wsl.exe then executes the complete "vendor/bin/captainhook" command inside the default wsl distro, which makes it a bit easier in case it triggers more complex npm commands etc.

My first attempt to solve this was to simply add the wsl.exe to the "php-path" config, but this failed since at src/Config/Factory.php:228 is a validation check which does not work in this context. We have recently introduced captainhook at our company and this could make life for wsl users a bit easier, but we can also wait for other input.

sebastianfeldmann commented 6 months ago

From my side I'm happy to merge this one. If it solves your problem this is a legit way to implement the WSL support and it can be further improved in the future if needed.

chriskapp commented 6 months ago

ok great, I have just updated the PR and marked it as ready