SVN post/pre commit hook 来检查 windows 上的 php 语法 [英] SVN post/pre commit hook to check php syntax on windows
问题描述
我最近将我的 SVN 服务器迁移到了 Windows 服务器.一切都进行得非常顺利 - 好得令人难以置信 - 结果就是这样.
I have recently migrated my SVN server to a windows server. It all went very smoothly - it was too good to be true - so it turned out.
我有/有一个预提交钩子,它对提交的任何 PHP 文件运行语法检查,如果检查失败,则拒绝提交并显示合适的错误消息 - 我将在下面复制它.显然这在 Windows 上不起作用,我也找不到替代方法.外面有人有东西吗?
I have/had a pre-commit hook which ran a syntax check on any PHP file committed and rejected the commit with a suitable error message if it failed the check - I will copy this below. Obviously this does not work on Windows, and I have not been able to find an alternative which does. Does anyone out there have anything?
我真的不知道从哪里开始转换以下内容以在 Windows 系统上运行,特别是考虑到它依赖的 *nix 工具的数量:-S
I wouldn't really know where to start converting the below to run on a Windows system, expecially given the number of *nix tools it is reliant on :-S
我已经阅读了关于使用 Codesniffer 之类的东西进行 PHP 检查的预提交钩子 - 是我最好/最简单的路线吗?
I have read about pre-commit hooks which use things like Codesniffer to do the PHP checks - is something like that my best/simplest route?
#!/bin/bash
REPOS="$1"
TXN="$2"
PHP="/usr/bin/php"
SVNLOOK=/var/www/UberSVN/ubersvn/bin/svnlook
CHANGED=`$SVNLOOK changed -t "$TXN" "$REPOS" | awk '{print $2}'`
ERRORSA=0
for LINE in $CHANGED
do
FILE=`echo $LINE | egrep \\.php$`
if [ $? == 0 ]
then
MESSAGE=`$SVNLOOK cat -t "$TXN" "$REPOS" "${FILE}" | $PHP -l`
if [ $? -ne 0 ]
then
ERRORSA=1
echo "---------------------------------------------------------------------------------" 1>&2
echo "${FILE}: $MESSAGE" | sed "s| -| $FILE|g" 1>&2
fi
fi
done
if [ $ERRORSA == 1 ]
then
echo "---------------------------------------------------------------------------------" 1>&2
echo "Please correct the errors and try commit again. $ERRORSA" 1>&2
exit 1
fi
exit 0
推荐答案
感谢我的同事,我将这个小问题传递给了他,对于任何未来的寻求者,下面是一个预提交钩子,它将执行 PHP在 Windows 托管的 SVN 服务器上进行语法检查(还检查用户是否输入了提交消息).希望其他人会发现这很有用:)
Credit goes to my colleague to whom I passed this little problem on to, and below for any future seekers, is a pre-commit hook which will do a PHP syntax check on Windows hosted SVN servers (also checks the user has entered a commit message). Hopefully someone else will find this useful :)
@echo off
:: Stops commits that don't include a log message of at least 6 characters.
@echo off
setlocal enableDelayedExpansion
rem Subversion sends through the repository path and transaction id
set REPOS=%1
set TXN=%2
svnlook log %REPOS% -t %TXN% | findstr ...... > nul
if %errorlevel% gtr 0 (goto err) else (goto cont)
:err
echo --------------------------------------------------------------------------- 1>&2
echo Your commit has been blocked because it didn't include a log message. 1>&2
echo Do the commit again, this time with a log message that describes your changes. 1>&2
echo --------------------------------------------------------------------------- 1>&2
exit 1
:cont
svnlook changed %REPOS% -t %TXN% |findstr /I /R "\.php$ \.phtml$" >lint.txt
for /F "tokens=2* delims= " %%i in (lint.txt) do (
set fname=%%i %%j
for /l %%a in (1,1,31) do if "!fname:~-1!"==" " set fname=!fname:~0,-1!
svnlook cat %REPOS% -t %TXN% "!fname!" | D:\PHP\php -l | findstr /I /B /V "No syntax errors" 1>&2
if !errorlevel! neq 1 (
echo in "%%i %%j" 1>&2
echo. 1>&2
echo --------------------------------------------------------------------------- 1>&2
exit 1
)
)
del lint.txt
这篇关于SVN post/pre commit hook 来检查 windows 上的 php 语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!