Force comments When SVN commits

Source: Internet
Author: User

Force comments When SVN commits

Many developers do not write comments when they submit changes, resulting in a difficult time to view history, but also not too well-qualified. How do you prevent developers from writing comments on tools that require bugs or task descriptions to be written every time they commit a change?
This requirement can be achieved simply by using SVN's pre-commit hooks.
Enter the warehouse Project1/hooks directory, locate the Pre-commit.tmpl file, rename it, and remove the suffix. Tmpl. Edit the Pre-commit file: (Linux system and Windows system script contents see 1 and 2)
1. Linux System

Method 1:

Will: $SVNLOOK log-t "$TXN" "$REPOS" | \ grep "[a-za-z0-9]" >/dev/null | | Exit 1 commit-access-control.pl "$REPOS" "$TXN" commit-access-control.cfg | | Exit 1 These three lines are commented out (preceded by a # symbol), where the following lines are added:
logmsg= ' $SVNLOOK log-t "$TXN" $REPOS "| grep "[A-za-z0-9]" | Wc-c ' If ["$LOGMSG"-lt 5]; #要求注释不能少于5个字符, you can customize then ECHO-E "\nlog message Cann ' t be empty! You must input more than 5 chars as comment!. " 1>&2 Exit 1 fi
Save, exit. Add executable permissions to Pre-commit: chmod +x Pre-commit Here remember to modify $SVNLOOK = (Svnlook path,/CSVN installation directory/bin/svnlook) configuration end, can be used.

Method 2:

These two days the project's development machine migrated to the Linux environment, with Python rewrite the original SVN hook, saved as pre-commit into the SVN hooks directory, chmod +x pre-commit plus execute permissions. Windows Write svn hooks is troublesome, can only be batch processing or exe,linux under whatever scripting language can be written, as long as the executable permission to go.

#! /usr/bin/env python#-*-coding:utf-8-*-"" "SVN check hook before submitting function: 1, mandatory fill in the submission of comments, content 10 bytes above 2, the mandatory annotation format is: xxx:xxx 3, mention Submit file check, filter not allowed file "" "Import Sysimport osimport redef Main (argv): (repos, TXN) = argv badlist = (". *config\.php $ ",". */php/cache ",". *test "," config\.js$ "," ^.*\.db$ ") message =" ". Join (Os.popen ("/usr/bin/svnlook log '%s '-t '% S ' "% (repos, TXN)). ReadLines ()). Strip () If Len (message) < 10:sys.stderr.write (" Please enter the modified content of this submission, 10 words Section above.                "); Sys.exit (1) If Message.find (': ') < 1:sys.stderr.write ("Please fill in the comments by specification in the format: function name: Modify the description.)                "); Sys.exit (1) changelist = Os.popen ("/usr/bin/svnlook changed '%s '-t '%s '"% (repos, TXN)). ReadLines () for Li                                NE in changelist:for pattern in badlist:if re.search (pattern, line): Sys.stderr.write ("Please do not add%s to the repository.                                "% Line[1:].strip ());    Sys.exit (1)    Sys.exit (0) If __name__ = = "__main__": Main (sys.argv[1:]) 

2. Windows Mandatory Comment Script

@echo off setlocal

Set repos=%1 set txn=%2

REM guaranteed input of 8 characters Svnlook log%repos%-T%txn% | Findstr "..." > nul if%errorlevel% gtr 0 goto:err_action

REM Filter space character Svnlook log%repos%-T%txn% |      Findstr/ic: "" > nul if%errorlevel% gtr 0 goto:success:err_action echo You submit a log description of any changes that were not filled in this release.  >&2 echo Please add the log description information and then submit the code, such as: function description. >&2 echo input log information not less than 8 characters description (or 4 kanji), thank you! >&2 echo ******************* Forbidden space data ***************** >&2

Goto:err_exit

: Err_exit exit 1:success exit 0

Force comments When SVN commits

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.