[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: RE : Checking for empty messages on pre-commit hook on windows

From: Gustavo Guerra <gustavguerra_at_gmail.com>
Date: 2006-03-05 00:36:08 CET

I've put both ways in the commit hook, and it still doesn't work. Any clues?

setlocal

set REPOS=%1
set TXN=%2
set SVNLOOK=svnlook
set GREP=grep
set PYTHON=python

c:
cd \SVNRoot\obiwan\hooks

set repos=%1
set txn=%2

%SVNLOOK% log -t %TXN% %REPOS% | %GREP% -qF "^$" temp.xpto
if '%errorlevel%'=='1' goto EMPTY_CHECK2
echo Empty commit messages are not allowed >&2
goto ERROR

:EMPTY_CHECK2
set COMMIT_LOG_IS_EMPTY=true
for /f "tokens=*" %%i in ('%SVNLOOK% log -t %TXN% %REPOS% ') do set COMMIT_LOG_IS_EMPTY=false
if '%COMMIT_LOG_IS_EMPTY%'=='false' goto AUTOVERSIONING_CHECK
echo Empty commit messages are not allowed >&2
goto ERROR

:AUTOVERSIONING_CHECK
%SVNLOOK% log -t %TXN% %REPOS% | %GREP% -qF "Autoversioning" temp.xpto
if '%errorlevel%'=='1' goto CHECK_CASE_INSENSITIVE
echo Autoversioning commit messages are not allowed >&2
goto ERROR

:CHECK_CASE_INSENSITIVE
%PYTHON% check-case-insensitive.py %REPOS% %TXN%
if '%errorlevel%'=='1' goto ERROR

%PYTHON% remove-trailing-newlines.py -t %TXN% %REPOS%
if '%errorlevel%'=='1' goto ERROR

exit /b 0

:ERROR
rem > pre-commit-messages.vbs echo WScript.Echo^( "Error found in commit."
^& vbCrLf ^& "Please check." ^)
rem wscript pre-commit-messages.vbs
rem del pre-commit-messages.vbs
exit /b 1

Best regards,
Gustavo Guerra

> Thanks for your tips
>
> How can I check the errorlevel directly on the cmd shell?
>
> Regards,
> Gustavo Guerra
>> Hi,
>>
>> First, I would advise against using temporary files as you did.. If
>> you
>> cannot make sure the temp filename is unique, you may endup with
>> conflicting
>> operations... It would be better to pipe the output of SVNLOOK
>> directly
>> into
>> GREP:
>> %SVNLOOK$ log -t %TXN% %REPOS% | %GREP% -qF "^$" temp
>> Now, regarding your problem there... I would suggest you the
>> following
>> avenues of investigation:
>> - try out manually the grep command and check the errorlevel output..
>> I
>> would think that the result would always be 0!
>> - I personnaly avoid using the 'if errorlevel N' statement. I often
>> had
>> problems with it I cannot explain. I personnally use a statement
>> like:
>> if '%errorlevel%'=='1'
>> - Use the /b on exit statement: exit /b 0
>> Finally, here is the pre-commit hook I am using. It is working fine!
>> One
>> of
>> the 'tricky' part is the for loop behavior!
>> - Empty lines would be automatically skipped and the DO part would
>> not
>> be
>> executed... So, if the log is totally empty the DO is never executed.
>> - If anything is present, the DO part is executed and bIsEmpty is set
>> to
>> false.
>> ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ @ECHO OFF
>> set repos=%1
>> set txn=%2
>> :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
>> :
>> :: Make sure that the log message contains some text.
>> :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
>> :
>> :: If the commit log is empty the for loop will not even run...
>> set bIsEmpty=true
>> for /f "tokens=*" %%g in ('svnlook log %repos% --transaction %txn%')
>> do (
>> set bIsEmpty=false
>> )
>> if '%bIsEmpty%'=='true' goto ERROR EMPTY
>> goto :eof
>>
>> :ERROR EMPTY
>> echo Empty commit logs are not allowed. >&2
>> goto ERROR EXIT
>> :ERROR EXIT
>> exit /b 1
>> ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
>> philibert
>> -----Message d'origine-----
>>
>>> De : news [mailto:news@sea.gmane.org] De la part de Gustavo Guerra
>>> Envoyé : 4 mars 2006 17:20
>>> À : users@subversion.tigris.org
>>> Objet : Checking for empty messages on pre-commit hook on windows
>>> Greetings,
>>> If tried this as pre-commit-hook.bat:
>>>
>>> set REPOS=%1
>>> set TXN=%2
>>> set SVNLOOK="c:\program files\subversion\bin\svnlook.exe"
>>> set GREP="c:\program files\gnuwin32\bin\grep.exe"
>>> %SVNLOOK$ log -t %TXN% %REPOS% > temp
>>> %GREP% -qF "^$" temp
>>> if errorlevel 1 goto OK
>>> echo Empty messages are not allowed 1>&2
>>> exit 1
>>> :OK
>>> exit 0
>>> But it doesn't work, commit is always allowed. Can anyone help?
>>> Regards,
>>> Gustavo Guerra
>>> --------------------------------------------------------------------
>>> -
>>> To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
>>> For additional commands, e-mail: users-help@subversion.tigris.org

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org
Received on Sun Mar 5 00:37:39 2006

This is an archived mail posted to the Subversion Users mailing list.