- windows环境下,修改svn的pre-commit hook以实现提交日志不能为空,限制文件大小和文件类型。
- 将下列代码复制粘贴进去即可。
bash
@echo off
setlocal enabledelayedexpansion
set REPOS=%1
set TXN=%2
rem 限制的文件大小byte
set MAX_SIZE=51200
for /f "delims=" %%a in ('svnlook changed -t %TXN% %REPOS%') do (
set var=%%a
for /f %%i in ('svnlook filesize -t %TXN% %REPOS% !var:~4!') do (
if %%i gtr %MAX_SIZE% (
set /a size=%%i/1024
echo 文件大小超出限制! File: !var:~4! Size: !size!KB 1>&2
goto err_fileSize
)
)
)
rem 日志不能为空,至少输入十个字符(几个点就是几个字符)
svnlook log %REPOS% -t %TXN% | findstr ".........." > nul
if %errorlevel% gtr 0 goto err_log
rem 限制文件类型
rem svnlook changed -t "%TXN%" "%REPOS%" | findstr "crf$"
rem if %errorlevel% EQU 0 (goto err_suffix)
rem svnlook changed -t "%TXN%" "%REPOS%" | findstr "d$"
rem if %errorlevel% EQU 0 (goto err_suffix)
rem svnlook changed -t "%TXN%" "%REPOS%" | findstr "o$"
rem if %errorlevel% EQU 0 (goto err_suffix)
exit 0
:err_log
echo 日志过短或为空!(不小于10个字符) 1>&2
exit 1
:err_fileSize
exit 2
:err_suffix
echo 请勿提交受限制的文件类型!(crf,d,o) 1>&2
exit 3