问题
I am configuring phpcs in Travis.
In order to check PHP code standard on commit push with travis CI.
I am using following script
script:
- phpcs --standard=PSR2 $(find ./ -name '*.php')
But this script checks each .php
file.
I need Travis to check only the current committed files.
Does someone has any solution for this case? Thanks in advance.
回答1:
What you could try is the following:
get last commit id: (How to get the last commit ID of a remote repo using curl-like command?)
git log --format="%H" -n 1
Then get files in last commit: (How to list all the files in a commit?)
git diff-tree --no-commit-id --name-only -r `git log --format="%H" -n 1`
You can see that previous command is used here. The first part before backtits needs a commit id to list files from. This commit id is found with the first command.
And then if you want only php files you can use grep :
git diff-tree --no-commit-id --name-only -r `git log --format="%H" -n 1` | grep .php
Output on one of my php project:
app/Http/Controllers/BarterController.php
app/Http/Controllers/HomeController.php
app/Talk.php
resources/views/profiles/index.blade.php
resources/views/talks/show-comments.blade.php
Simply replace your command $(find ./ -name '*.php')
with the one I gave above and it should work. Your command would become the following:
phpcs --standard=PSR2 $(git diff-tree --no-commit-id --name-only -r `git log --format="%H" -n 1` | grep .php)
来源:https://stackoverflow.com/questions/50128549/travis-configuration-of-phpcs-for-only-current-commit-files