It is no secret that by default, changing the text of the comment to the revision in SVN is not allowed. The post is intended for those who want to make it possible, but do not know how.
First, let's refresh our memory a little.
What is a hook.
No, this is not a Spielberg film, we are on a habr. This is the hook that caught the event :) Just a program that runs when a specific event occurs in the version control system. They are supported not only by SVN, so you can play around with hooks for example in GIT.
If there is a hooks folder in the root of your repository, you should know that this is the hooks nest. Hook templates can be stored in this folder, the names of which correspond to the events being tracked.
$ ls repos/hooks/ post-commit.tmpl post-unlock.tmpl pre-revprop-change.tmpl post-lock.tmpl pre-commit.tmpl pre-unlock.tmpl post-revprop-change.tmpl pre-lock.tmpl start-commit.tmpl $
This means that based on these patterns you can make your hook. As you may have guessed, pre-hooks are triggered before the event. post-hooks - after the event.
*
start-commit - runs before the start of the transaction, can be used to verify rights.
*
pre-commit - runs at the end of a transaction, but before commit, it is often used to validate data, for example, to check non-empty log messages.
*
post-commit - runs after a transaction, can be used to send e-mail or to reserve storage.
*
pre-revprop-change - run before changes in revision, can be used to check access.
*
post-revprop-change - run after changes in revision, can be used to send e-mail.
*
post-lock ,
post-unlock ,
pre-lock ,
pre-unlock - run when the repository works with locks
It would not be superfluous to mention that the user who connects to the repository, and therefore runs the hooks, must have execution rights.
')
Change Revision Comment
Let us turn to the solution of our problem. Use the pre-revprop-change hook to introduce additional controls. In addition, it should be remembered that the following parameters are passed to the hook
1. Path to the repository
2. Audit, whose properties will change
3. The name of the user who will make the changes
4. Name of changeable property
5. Action code: A (added), D (deleted), or M (modified)
Hook right.
In * nix systems, it is enough to create the corresponding file in the
hooks folder without an extension, for example,
pre-revprop-change #!/bin/sh # . REPOS="$1" REV="$2" USER="$3" PROPNAME="$4" ACTION="$5" # ( ) if [ "$ACTION" = "M" -a "$PROPNAME" = "svn:log" ]; then exit 0 else echo "Changing revision properties other than svn:log is prohibited" >&2 exit 1 fi
Hook left.
On Windows, the file in the
hooks folder must be executable, for example,
pre-revprop-change.bat @ECHO OFF :: . set repository=%1 set revision=%2 set userName=%3 set propertyName=%4 set action=%5 :: ( ) if /I not "%propertyName%" == "svn:log" goto ERROR_PROPNAME :: ( ) if /I not "%action%" == "M" goto ERROR_ACTION :: , . set bIsEmpty=true for /f "tokens=*" %%g in ('find /V ""') do ( set bIsEmpty=false ) if "%bIsEmpty%" == "true" goto ERROR_EMPTY goto :eof :ERROR_EMPTY echo Empty svn:log messages are not allowed. >&2 goto ERROR_EXIT :ERROR_PROPNAME echo Only changes to svn:log messages are allowed. >&2 goto ERROR_EXIT :ERROR_ACTION echo Only modifications to svn:log revision properties are allowed. >&2 goto ERROR_EXIT :ERROR_EXIT exit /b 1
If you are using a VisualSVN server, the default batch file will not work. And the folder hooks do not need to create. You just need to open the
VisualSVN Server Manager , go to the properties of the repository for which you want to create a hook, select the
Hooks tab. Double click on the
Pre-revision property change hook and just copy the code of the batch file there.
Addition: when activating a hook in the VisualSVN Server Manager, the server will create the hooks folder and generate standard templates there.
Thanks for the tip chemodaxPS All the information and codes for the hook found on the Internet