Reputation: 3859
We are using SVN and I would like to check the commit message for an string and give a warning that commits without this string will be bounced starting next month but currently allow the commit through.
stderr is only outputted when the commit fails, how do I allow the commit to succeed but still provide output to the user (I am writing the hook in C#)?
Upvotes: 0
Views: 276
Reputation: 164
Per your response above, here is the windows batch solution.
In the post-commit hook
:: repos = full path to physical repository
:: rev = the revision number related to the transaction committed
:: reposname = the name of the repository
set repos=%1
set rev=%2
set reposname=%~nx1
set Unwanted_String=string value
:: Capture commit message
svnlook log %repos% -r %rev%>%reposname%_%rev%_commit_statement.txt
:: Verify commit message meets requirements
powershell -command "If (Get-Content '%reposname%_%rev%_commit_statement.txt' | Where-Object { $_ -match '%Unwanted_String%'}) {'Found'} else {'Not found'}">%reposname%_%rev%_Is_String_Present.txt
:: Determine if feedback is needed
set /p Commit_Search=<%reposname%_%rev%_Is_String_Present.txt
if "%Commit_Search%"=="Found" (
echo ----------------------------------------------------->&2
echo The string %Unwanted_String% is not allowed >&2
echo In the future, please do not include this as part of your commit statement >&2
echo. >&2
echo Your change has been committed>&2
echo ----------------------------------------------------->&2
del *%reposname%_%rev%*.txt
exit /b 1
)
The output back to the user will show the object was committed along with an error message
post-commit hook failed (exit code 1) with output:
The string xxxxxx is not allowed
In the future, please do not include this as part of your commit statement
Your change has been committed
Once the grace period is over and you want to reject commit statements that contain this string, move the above lines to your pre-commit hook with one change
:: Capture commit message (-t is transaction in progress)
svnlook log -t %rev% %repos%>%reposname%_%rev%_commit_Statement.txt
Moving this to the pre-commit hook will prevent the commit and inform the user as to why it was rejected.
Upvotes: 1