0

我最近将我的 SVN 服务器迁移到了 windows 服务器。一切都进行得非常顺利——这太好了,令人难以置信——所以事实证明。

我有/有一个预提交钩子,它对任何提交的 PHP 文件进行语法检查,如果检查失败,则拒绝提交并显示合适的错误消息 - 我将在下面复制它。显然,这在 Windows 上不起作用,我还没有找到替代方法。外面有人有吗?

我真的不知道从哪里开始转换以下内容以在 Windows 系统上运行,特别是考虑到它所依赖的 *nix 工具的数量:-S

我已经阅读了有关使用 Codesniffer 之类的东西来进行 PHP 检查的预提交钩子 - 这是我最好/最简单的路线吗?

#!/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
4

1 回答 1

0

归功于我的同事,我将这个小问题传递给了他,下面对于任何未来的寻求者来说,是一个预提交钩子,它将在 Windows 托管的 SVN 服务器上进行 PHP 语法检查(也检查用户是否输入了提交消息)。希望其他人会发现这很有用:)

@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
于 2014-05-27T08:22:06.050 回答