Svn adds mandatory comments. pre-commit is combined with python and svnpre-commit.
Some people in the group do not write comments when submitting code, and there is no fixed format, so they are prepared to add mandatory comments when submitting code to svn.
First, find the hooks directory in the code library. This directory is available when the svn library is created normally. Go to the hooks directory, find the pre-commit.tmpl, remove tmpl, and rename it pre-commit.
This is a shell script. If the comment content cannot be less than a few characters, you can directly write the shell script. But now I want developers to submit code in a fixed format,
For example:
Reason: E-commerce
Developer: du
Reviewer: du
Shell should be able to do the same, but I am not very familiar with shell, and it is easier to write python, so I used a shell and python Method for hook.
First, use the python script.
Check. py
#coding=utf-8import sys inputstr = sys.argv[1]if inputstr=="": exit(1);lstr=inputstr.split("\n")if len(lstr)==3: if ('reason:' in lstr[0] and len(lstr[0])>len('reason:')) and ('developer:' in lstr[1] and len(lstr[1])>len('developer:')) and ('reviewer:' in lstr[2] and len(lstr[2])>len('reviewer:')): exit(0); else: exit(1); else: exit(1);
Then pre-commit
#!/bin/shSVN_BINDIR=/opt/subversion/bin/svnlookREPOS="$1"TXN="$2"LOGMSG=`$SVN_BINDIR log -t "$TXN" "$REPOS"`var=`python /opt/svndata/repos/hooks/check.py "${LOGMSG}"`result=$?if [ $result -gt 0 ]thenecho -e "you must input comment like this:\r\nreason:\r\ndeveloper:\r\nreviewer:" 1>&2exit 1fiexit 0
We recommend that you use vim to write this pre-commit file. If you do not write it in windows and upload it to the linux server, a format error will be reported. In fact, 1> & 2,-e should also be added, only when both of them are added can the error message be displayed when the client submits the request.
Both $ result and "$ result" can be referenced in shell, but do not use single quotes. If [$ result-gt 0] must be left with spaces. Otherwise, an error will be reported.
Verify as follows:
Submit without comments
Will prompt
The above error is caused by the system. It is mainly the prompt in the red box in the middle. We can see that the Force annotation is successfully added.
----------------
From this example, we can fully meet other requirements, such as submitting code and sending emails and recording logs into the database.