Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

STDIN is ignored in PHP 7.4.7 #787

Closed
melkamar opened this issue Jul 13, 2020 · 1 comment
Closed

STDIN is ignored in PHP 7.4.7 #787

melkamar opened this issue Jul 13, 2020 · 1 comment
Labels

Comments

@melkamar
Copy link

melkamar commented Jul 13, 2020

Q A
Version GrumPHP 0.19.1
Bug? yes
New feature? no
Question? no
Documentation? no
Related tickets #770

My configuration

grumphp:
    ascii: ~
    tasks:
        phpcsfixer2:
            config: "app/phpcs/.php_cs"
            diff: true
            verbose: true

Steps to reproduce:

# Generate empty folder
mkdir tmp
cd tmp
git init
echo "vendor" > .gitignore
pbpaste > grumphp.yml
composer require --dev phpro/grumphp

# Make any change, doesn't matter

# Run GrumPHP:
git add -A && git commit -m"Test"
# or
./vendor/bin/grumphp run

Result:

In ParserBase.php line 87:

  No match for regexp /diff --git (a\/.*) (b\/.*)\n/ Upcoming: diff --git c/i
  nstallation.yml


git:pre-commit [--skip-success-output] [-h|--help] [-q|--quiet] [-v|vv|vvv|--verbose] [-V|--version] [--ansi] [--no-ansi] [-n|--no-interaction] [-c|--config CONFIG] [--] <command>

Comment

This error only happens after upgrading to PHP 7.4.7 from 7.3.x.

After upgrading to PHP 7.4, grumphp ignores the STDIN stream. Regardless of what I pass in, it always ignores it and goes with the default "no stdin provided" route. The command I use to call the tool is (truncated):

$ DIFF=$(git -c diff.mnemonicprefix=false --no-pager diff -r -p -m -M --full-index --no-color --staged | cat)
$ (cd "./" && printf "%s\n" "${DIFF}" | 'exec' 'vendor/bin/grumphp' 'git:pre-commit' '--skip-success-output')

The importance of calling the script with a custom STDIN is in the -c diff.mnemonicprefix=false config used to generate the git diff. Without this config the diff is in a format that causes the ParserBase exception shown above.

I have traced the issue to this line of code: ConsoleIO:86. Here the ftell() function returns false, which means that an empty string is returned from the method. If I change the line to

if (0 !== ftell($handle) && false !== ftell($handle)) {

then everything works as expected and the stdin passed to grumphp is recognised. But I don't know if that is a sufficient fix as this might potentially hide other issues.

@veewee
Copy link
Contributor

veewee commented Jul 13, 2020

Thanks @melkamar for the very detailed report.
I've created a fix for the stdin issue in #788. Looks like that one slipt in a couple of years ago.

To fix the invalid diff issue, you could change your git config or try changing it in the gitlib package.
More info:

@veewee veewee closed this as completed Jul 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants