You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@subversion.apache.org by Philibert Pérusse <pp...@gsmproducts.ca> on 2006/03/04 22:54:04 UTC

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

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


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

Posted by Gustavo Guerra <gu...@gmail.com>.
The problem isn't the paths, the second check for the string "Autoversioning" 
in the message works. 

Gustavo Guerra

> On Mar 5, 2006, at 00:36, Gustavo Guerra wrote:
> 
>> I've put both ways in the commit hook, and it still doesn't work.
>> Any clues?
>> 
> Does that work when you run it manually from the command line? I
> don't know Windows, but I'm having a hard time seeing how it would
> know where svnlook, grep and python are located, since you haven't
> specified absolute paths to them, which it's usually advisable that
> you do, since the hook runs without the usual environment variables
> you have in a shell.
> 
>> 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




---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org

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

Posted by Ryan Schmidt <su...@ryandesign.com>.
On Mar 5, 2006, at 00:36, Gustavo Guerra wrote:

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

Does that work when you run it manually from the command line? I  
don't know Windows, but I'm having a hard time seeing how it would  
know where svnlook, grep and python are located, since you haven't  
specified absolute paths to them, which it's usually advisable that  
you do, since the hook runs without the usual environment variables  
you have in a shell.

> 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




---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org

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

Posted by Gustavo Guerra <gu...@gmail.com>.
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

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

Posted by Gustavo Guerra <gu...@gmail.com>.
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