仅针对当前提交文件的Tracs配置phpcs [英] Travis configuration of phpcs for only current commit files

查看:67
本文介绍了仅针对当前提交文件的Tracs配置phpcs的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Travis中配置phpcs。

为了在使用Travis CI进行提交推送时检查PHP代码标准。

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')

但是此脚本会检查每个 .php 文件。
我需要Travis仅检查当前提交的文件。

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.

推荐答案

您可以尝试以下操作:

获取最后的提交ID:(如何使用类似curl的命令获取远程仓库的最后提交ID?

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`

您可以看到此处使用了先前的命令。反击之前的第一部分需要提交ID才能列出文件。可以通过第一个命令找到该提交ID。

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.

然后,如果只需要php文件,则可以使用grep:

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

我的一个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

只需将我的命令 $(find ./ -name'* .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)

这篇关于仅针对当前提交文件的Tracs配置phpcs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆