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

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

From: Philibert Pérusse <pperusse_at_gsmproducts.ca>
Date: 2006-03-04 23:54:04 CET

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 Sat Mar 4 23:55:17 2006

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

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.