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

Add support for inter branch diffs #28

Closed david-binda closed 4 years ago

david-binda commented 4 years ago

When phpcs-changed is used in CI (eg.: Travis), there is no good way to determine the unified diff, since the working directory is clean.

In order to accommodate the situation when a branch or PR is being checked, a support for inter branch diff is helpful.

This PR adds a new param git-branch: which instructs the phpcs-changed to run a diff of the current working directory against specified branch (eg.: master).

A usage in Travis would be, for instance, as follows:

script:
  - if [[ "$SNIFF" == "1" ]] && [[ "$TRAVIS_PULL_REQUEST" != "false" ]]; then /tmp/phpcs-changed/bin/phpcs-changed --git --git-branch "$TRAVIS_BRANCH" --standard="WordPress-VIP-Go" .; fi

For the needs of checking whether a file is a new one, the UnixShell::executeCommand method had to be changed to use exec rather than shell_exec, as exec also provides support for reading the exit code. In order to make the UnixShell::executeCommand backward compatible, I'm joining the $output with PHP_EOL + appending one to the very end.

See #25

david-binda commented 4 years ago

@sirbrillig have added the integration test. Back at ya for the review :)

sirbrillig commented 4 years ago

Looks great! Thank you!