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
1.01k stars 87 forks source link

[Bug?] Pre-push hook failing with ddev/docker #250

Closed mm-bfu closed 5 months ago

mm-bfu commented 5 months ago

We use a basic configuration with ddev. All hooks work well, except for the pre-push hook.

captainhook.json:

"config": {
        "run-mode": "docker",
        "run-exec": "ddev exec",
        "run-path": "/var/www/html/vendor/bin/captainhook"
},
"pre-push": {
        "enabled": true,
        "actions": [
            {
                "action": "composer run-cs-fixer"
            },
            {
                "action": "composer run-phpmd"
            },
            {
                "action": "composer run-psalm"
            },
            {
                "action": "composer run-security-check"
            }
        ]
    }

The error:

Command "c678d6c26ffa8b5df0a9483a7ac67c953f9c43c0" is not defined.

Failed to execute command /var/www/html/vendor/bin/captainhook --bootstrap=vendor/autoload.php --input=refs/heads/bugfix/prePushHook c678d6c26ffa8b5df0a9483a7ac67c953f9c43c0 refs/heads/bugfix/prePushHook 0000000000000000000000000000000000000000 hook:pre-push origin git@bitbucket-xxxxxx:xxxxxx/project-foo.git: exit status 1

What I noticed: Captain hook creates the following command in .git/hooks/pre-push:

ddev exec /var/www/html/vendor/bin/captainhook --bootstrap=vendor/autoload.php --input="$input" hook:pre-push "$@"

Possible fix: It works when I add escaped double quotes around the input option:

ddev exec /var/www/html/vendor/bin/captainhook --bootstrap=vendor/autoload.php --input=\""$input"\" hook:pre-push "$@"

Questions:

Thank you!

sebastianfeldmann commented 5 months ago

No you are right that's looks like an encoding issue because of the whitespaces in the multiple commit hashes string.

I will update the template and make sure the quoting works properly.

sebastianfeldmann commented 5 months ago

Strange for me the double quotes are working the way they should. I don't get the error :/

Tested on MacOS with zsh and bash. What environment are you working with?

sebastianfeldmann commented 5 months ago

Forget what I said you are using the docker mode and then the command already is an argument so using the additional quotes makes sense, at least somehow ;)

sebastianfeldmann commented 5 months ago

I just released version 5.23.1

I you re-install your hooks they should be installed with the appropriate quoting. If you have any issues feel free to re-open the issue.

Thanks for reporting the issue and looking for a solution. Greatly appreciated