当前位置: 首页 > 科技观察

关于SVN提交强制添加评论

时间:2023-03-13 22:01:23 科技观察

本文转载自微信公众号《UP技控》,作者conan5566。转载本文请联系UP技控公众号。背景在项目开发过程中,团队中总有人忘记添加评论。解决方案1.如果我们能把这个工作交给计算机不是更好吗?2.提交代码时,电脑会自动提醒。3.代码注释数量有限。以下是最少5个字符的示例。实现方法方法一1、用户提交代码的动作对应pre-commit。因此,可以修改pre-commit.tmpl文件。文件名改为pre-commit,Windows下可以改为pre-commit.bat。这让系统知道该文件是可执行的。#!/bin/sh#PRE-COMMITHOOK##Thepre-commithookisinvokedbeforeaSubversiontxnis#committed.Subversionrunsthishookbyinvokinaprogram#(script,executable,binary,etc.)named'pre-commit'(forwhich#thisfileisatemplate),withthefollowingorderedarguments:##[1]回购-PATH(到此存储库的路径)#[2]TXN-NAME(即将提交的txna的名称)##[STDIN]LOCK-TOKENS**锁令牌通过STDIN传递。##如果STDIN包含行“LOCK-TOKENS:\n”(“\n”表示#singlenewline),则其后的行是锁令牌#thiscommit.Theendofthelistismarkedbyalinecontaining#onlyanewlinecharacter.##EachlocktokenlineconsistsofaURI-escapedpath,followed#bytheseparatorcharacter'|',followedbythelocktokenstring,#followedbyanewline.##Thedefaultworkingdirectoryfortheinvocationisundefined,so#theprogramshouldsetoneexplicitlyifitcares.##Ifthehookprogramexitswithsuccess,thetxniscommitted;but#ifitexitswithfailure(non-zero),thetxnisaborted,nocommit#takesplace,并且STDERR返回到客户端。Thehook#program可以使用'svnlook'实用程序来帮助检查thetxn。##OnaUnix系统,正常过程是'预提交'#invokeother程序做真正的工作,虽然它也可以做#workitself。作者)。***##Thisiswhywerecommendedusingtheread-only'svnlook'utility.#Inthefuture,Subversionmayenforcetheruletthatpre-commit#hooksshouldnotmodifytheversioneddataintxns,orelsecome#upwithamemechanismtomakeitssafetodoso(通过通知#committingclientofthechanges)。然而,现在既不#mechanismispreimplemented,所以mitthathookwriters.comjusthavetobe必须由将#invokeit的用户执行(通常是用户httpdrunsas),并且该用户必须#havefilesystem-levelpermissiontoaccesstherepository。ntprocess.Forexample,acommonproblemisforthe#PATHenvironmentvariabletonotbesettoitsusualvalue,so#thatsubprogramsfailtolaunchunlessinvokedviaabsolutepath.#Ifyou'rehavingunexpectedproblemswithahookprogram,the#culpritmaybeunusual(ormissing)environmentvariables.##Hereisanexamplehookscript,foraUnix/bin/shinterpreter.#Formoreexamplesandpre-writtenhooks,seethosein#theSubversionrepositoryat#http://svn.apache.org/repos/asf/subversion/trunk/tools/hook-scripts/and#http://svn.apache.org/repos/asf/subversion/trunk/contrib/hook-scripts/REPOS="$1"TXN="$2"#Makesurethatthelogmessagecontainssometext.SVNLOOK=/usr/local/bin/svnlookSVNLOOKlog?t"TXN""$REPOS"|\grep[a-zA-Z0-9]">/dev/null||exit1#Checkthattheauthorofthiscommithastherrightstopperform#thecommitonthefilesanddirectoriesbeingmodified.commit-access-control.pl"REPOS""TXN"commit-access-control.cfg||exit1#Allcheckspassed,所以允许提交。exit0明确将pre-commit文件的内容复制到pre-commit文件中:@echooffsetlocalsetREPOS=%1setTXN=%2remcheckthatlogmessagecontainsatleast10charactersrem.....代表5个字符svnlooklog"%REPOS%"-t"%TXN%"|findstr".........">nulif%errorlevel%gtr0gotoerrexit0:errechoEmptylogmessagenotallowed.Commitaborted!1>&2exit12,给pre-commit添加可执行权限:chmod+xpre-commit方法二,直接在客服端设置是通过TortoiseSvn。在本地副本中,选择项目,右键选择TortoiseSvn,选择属性,添加tsvn:logminsize,将值限制为10。添加logminsize属性后,必须提交本地工作副本才能生效,如下图:效果图