Skip to content

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

Open
@vardrop

Description

@vardrop

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions