I want to edit the incoming commit messages (adding branch name, or add a template that has some lines ignored etc). While I was searching I found that git has a prepare commit message hook that seems to do this but svn doesn't. Is there a way to do this in svn before the post commit?
In SVN you do not need to use hook scripts to add log message templates:
With TortoiseSVN client, you can and should use tsvn:*
properties.
With vanilla svn.exe command-line client, use CMD_EDITOR
environment variable to define which log message you want to call or make it determine the log message automatically based on the changes in your commit.
Adjusting log messages for existing revisions in SVN is normally a one-line command. It is forbidden to modify the log messages, by default. An admin can always allow this to all or only certain users.
I guess that you already use TortoiseSVN client since the question is marked with windows tag. TortoiseSVN supports several properties that should help you define the behavior of the client. They will help you implement commit policies including log message restrictions and templates:
tsvn:logminsize
defines minimum number of characters the log message of the incoming revision must contain.
tsvn:logtemplate
will help you define default log message template. There are 8 additional tsvn:logtemplate
properties that you can use to add different templates for different types of commits.
tsvn:logsummary
will help you define regexp to grab a portion of commit message and display it as a summary when you view revision history log with TortoiseSVN.
See the TortoiseSVN Project Properties chapter of the manual for complete list of properties and their purpose.
You must use git's pre-commit
hooks to validate the log messages and add commit message templates. If you don't do this, the procedure to fix the mistakes in log messages requires you to use git rebase
that can be non-trivial. There could be other ways to add log message policies, but in git's world you have to use hook scripts for this.
Don't forget that svn commit
and git commit
operations play different roles in common workflows with git or SVN. The whole idea and results of svn commit and git commit operations is different. Consequently, *-commit
hooks have different goals in both systems:
Running git commit in your local git repository is a local, client-side only operation. When you commit in git, you only make a local snapshot without contacting the blessed remote repository. In this case it should be perfectly fine to use local hooks to customize client's default behavior. Your local changes do not affect other git users unless you publish them by pushing or pulling. And this is the part of git's workflow that requires you to take maximum care about the log messages -- rewriting the commit's data (including the log message) will force your colleagues to put aside current tasks and begin manual repair of their local repos.
But when you run svn commit, you contact the remote server to publish your local changes to the repository and make them available in form of new revision to other developers. Even if you made a mistake in log message when you commit to SVN, you can always adjust it yourself or ask a colleague who has such privilege. Simple and no harm caused.