簡體   English   中英

SVN post / pre commit鈎子,用於檢查Windows上的php語法

[英]SVN post/pre commit hook to check php syntax on windows

我最近將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

我的同事將這個小問題傳遞給我的同事,以及對以后的任何尋求者而言,是一個預先提交的掛鈎,它將在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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM