composer-git-hooks icon indicating copy to clipboard operation
composer-git-hooks copied to clipboard

windows composer array scripts as cghooks, only first gets executed when testing by invoking cghooks ${hook}

Open vardrop opened this issue 3 years ago • 2 comments

You can reconstruct this bug by using vardrop/cghooks-test

Description

When defining an array as a composer git hook on windows, only the first in the array gets executed. This bug may be related to running in windows as running the same project in wsl will result in the expected output.

composer.json

{
    "require-dev": {
        "brainmaestro/composer-git-hooks": "^2.8"
    },
    "scripts": {
        "post-install-cmd": "cghooks add --ignore-lock",
        "post-update-cmd": "cghooks update",
        "cghooks": "vendor/bin/cghooks"
    },
    "extra": {
        "hooks": {
            "pre-commit": [
                "echo 1 lorem ipsum",
                "echo 2 dolor eset"
            ]
        }
    },
    "require": {
        "php": "^8.0"
    }
}

I have confirmed that the second script above never actually gets called by replacing echo 2 dolor eset with touch test.txt.

Versions

  • Windows 10 Version 20H2 Build 19042.985
$ php -v
PHP 8.0.7 (cli) (built: Jun  2 2021 00:41:03) ( ZTS Visual C++ 2019 x64 )
Copyright (c) The PHP Group
Zend Engine v4.0.7, Copyright (c) Zend Technologies

$ composer -V
Composer version 2.1.2 2021-06-07 16:03:06

$ composer show brainmaestro/composer-git-hooks | rg versions
versions : * v2.8.5

$ git --version
git version 2.31.1.windows.1

Expected

When running composer cghooks pre-commit, Id expect the output to be

$ composer cghooks pre-commit
> vendor/bin/cghooks 'pre-commit'
1 lorem ipsum
2 dolor eset

Actual

but given the above configuration it will result in

$ composer cghooks pre-commit
> vendor/bin/cghooks "pre-commit"
1 lorem ipsum

Exceptions

Nevertheless, running git commit works as expected

$ git commit -m "feat: init"
1 lorem ipsum
2 dolor eset
[master (root-commit) 2c129d4] feat: init
(abbreviated)

vardrop avatar Jun 07 '21 19:06 vardrop

Hi @vardrop this seems a bit strange especially because when the hook is executed by git itself, it works as expected. Unfortunately, I do not have a Windows machine to reproduce and investigate. Are you willing to do some more investigation? I can assist if needed

BrainMaestro avatar Jul 26 '21 12:07 BrainMaestro

Also, thanks a lot for the very detailed report and even a test repo to reproduce it. That's amazing! I wish I could be of more help

BrainMaestro avatar Jul 26 '21 12:07 BrainMaestro