phpro / grumphp

A PHP code-quality tool
MIT License
4.14k stars 430 forks source link

Error after removing a file #242

Closed Henk8 closed 7 years ago

Henk8 commented 7 years ago
Q A
Branch master
Bug? yes
New feature? no
Question? no
Documentation? no
Related tickets

My configuration

parameters:
    bin_dir: "./vendor/bin"
    git_dir: "."
    stop_on_failure: true
    tasks:
        phpcs:
            standard: "PSR2"

Steps to reproduce: create a new file and add it to your git repository. Commit the file. Remove the file an try to commit your project again.

Run GrumpHP: git add -A && git commit -m"Test"

Result:

</fg=red>
ERROR: The file "new_file.php" does not exist.
veewee commented 7 years ago

Hi @Henk8,

Can you give me some advanced steps to reproduce this error? Which version of PHP, GIT and GrumPHP are you using? Can you run grumphp with -vvv option and paste the result here?

I've tried following steps:

mkdir tmp && cd tmp
git init
composer require --dev phpro/grumphp
pbpaste > grumphp.yml
echo "vendor" > .gitignore
git add -A && git commit -m"initial commit"
echo "<?php" > somefile.php
git add somefile.php
git commit -m"somefile" somefile.php
rm somefile.php
git add -A && git commit -m"Remove file"

This works as expected.

Henk8 commented 7 years ago

PHP 5.6.29, git 2.11.0.0 and the latest build of grumphp.

I've tried performed the following steps:

Then I got the error

veewee commented 7 years ago

Ok, now I can reproduce the error. After running:

The new_file.php is still not added to git. When I run git status after the commit, I get:

On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

    new file:   new_file.php

After removing the file, I get this status:

On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

    new file:   new_file.php

Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    deleted:    new_file.php

As you can see, there is both a new file and a deleted file. This is probably what goes wrong.

During the commit, you can see following diff:

[2016-12-12 14:51:44] GrumPHP.INFO: run command: diff "-r -p -m -M --full-index --staged"  [] []
[2016-12-12 14:51:44] GrumPHP.DEBUG: last command (diff) duration: 6.58ms [] []
[2016-12-12 14:51:44] GrumPHP.DEBUG: last command (diff) return code: 0 [] []
[2016-12-12 14:51:44] GrumPHP.DEBUG: last command (diff) output: diff --git a/new_file.php b/new_file.php new file mode 100644 index 0000000000000000000000000000000000000000..4700ee3dfb6368aa0ee725c81511dba876cb0cfb --- /dev/null +++ b/new_file.php @@ -0,0 +1 @@ +<?php echo "Test"  [] []
Command: '/Users/verweto/.composer/vendor/bin/phpcs' '--standard=PSR2' '--report-full' '--report-json' 'new_file.php'

Result:
ERROR: The file "new_file.php" does not exist.

We could do an additional check to see if the file exists before passing it to the tasks. This way we won't get this error again.

In the meantime, you can just run the git add -A command before committing.

Henk8 commented 7 years ago

Thanks for looking in to it

veewee commented 7 years ago

No problem, thanks for reporting! I'll keep this issue open to make sure it gets solved in the next version.

veewee commented 7 years ago

This issue got fixed in PR #247 and will be released with next version.