sirbrillig / phpcs-changed

🐘 Run phpcs on files and only report new warnings/errors compared to the previous version.
MIT License
31 stars 11 forks source link

Use different commands for new files based on git mode #39

Closed sirbrillig closed 3 years ago

sirbrillig commented 3 years ago

When using the various git modes, the way to determine the contents of the "new" version of a file differs. Using git-unstaged, we can cat the working copy of the file; using git-staged, we must ask git for the staged version; using git-branch, we must ask git for the committed version.

An oversight in https://github.com/sirbrillig/phpcs-changed/pull/18 meant that the first two modes used the current working copy of the file. This PR fixes that bug by using the staged version for git-staged.

The third mode is a little more complicated. https://github.com/sirbrillig/phpcs-changed/pull/28 added the git-branch mode, and based on the description, it was intended to also use the current working copy of the file. However, in https://github.com/sirbrillig/phpcs-changed/pull/31 and https://github.com/sirbrillig/phpcs-changed/pull/34 I added documentation for that mode and incorrectly specified that it used the currently committed version of the code to compare to the HEAD of another branch. This PR changes the mode's behavior to match the documentation, using the current HEAD for git-branch. While I think this should be safe (the use-case given in the original PR was running the changes through CI, which is probably always operating on the committed file), I want to double check with @david-binda to make sure.

Fixes https://github.com/sirbrillig/phpcs-changed/issues/37

sirbrillig commented 3 years ago

I'm going to merge this as-is because I think it's the right behavior, but I won't cut a release until I'm sure that I can treat this as a non-breaking change.

david-binda commented 3 years ago

Thanks for addressing the issue! The solution seems to be working fine for me. 🙇