关于SVN提交强制加入注释

系统
用户提交代码的动作,对应的是pre-commit。因此,可以修改pre-commit.tmpl文件。 文件名修改为pre-commit, Windows下可以修改为pre-commit.bat。这样可以让系统知道该文件时可执行文件。

 [[377595]]

本文转载自微信公众号「UP技术控」,作者conan5566  。转载本文请联系UP技术控公众号。 

背景

在开发项目过程中,团队中总是有人忘记添加注释。

解决思路

1、我们可以把这项工作交给电脑来完成岂不是更好。

2、提交代码的时候电脑自动提醒。

3、代码注释字数限制。以下为最少5个字为例子。

实现方法

方式一

1、用户提交代码的动作,对应的是pre-commit。因此,可以修改pre-commit.tmpl文件。 文件名修改为pre-commit, Windows下可以修改为pre-commit.bat。这样可以让系统知道该文件时可执行文件。

  1. #!/bin/sh 
  2.  
  3. # PRE-COMMIT HOOK 
  4.  
  5.  
  6. # The pre-commit hook is invoked before a Subversion txn is 
  7.  
  8. committed.  Subversion runs this hook by invoking a program 
  9.  
  10. # (script, executable, binary, etc.) named 'pre-commit' (for which 
  11.  
  12. # this file is a template), with the following ordered arguments: 
  13.  
  14.  
  15. #   [1] REPOS-PATH   (the path to this repository) 
  16.  
  17. #   [2] TXN-NAME     (the name of the txn about to be committed
  18.  
  19.  
  20. #   [STDIN] LOCK-TOKENS ** the lock tokens are passed via STDIN. 
  21.  
  22.  
  23. #   If STDIN contains the line "LOCK-TOKENS:\n" (the "\n" denotes a 
  24.  
  25. #   single newline), the lines following it are the lock tokens for 
  26.  
  27. #   this commit.  The end of the list is marked by a line containing 
  28.  
  29. #   only a newline character
  30.  
  31.  
  32. #   Each lock token line consists of a URI-escaped path, followed 
  33.  
  34. #   by the separator character '|', followed by the lock token string, 
  35.  
  36. #   followed by a newline. 
  37.  
  38.  
  39. # The default working directory for the invocation is undefined, so 
  40.  
  41. # the program should set one explicitly if it cares. 
  42.  
  43.  
  44. # If the hook program exits with success, the txn is committed; but 
  45.  
  46. # if it exits with failure (non-zero), the txn is aborted, no commit 
  47.  
  48. # takes place, and STDERR is returned to the client.   The hook 
  49.  
  50. # program can use the 'svnlook' utility to help it examine the txn. 
  51.  
  52.  
  53. On a Unix system, the normal procedure is to have 'pre-commit' 
  54.  
  55. # invoke other programs to do the real work, though it may do the 
  56.  
  57. work itself too. 
  58.  
  59.  
  60. #   ***  NOTE: THE HOOK PROGRAM MUST NOT MODIFY THE TXN, EXCEPT  *** 
  61.  
  62. #   ***  FOR REVISION PROPERTIES (like svn:log or svn:author).   *** 
  63.  
  64.  
  65. #   This is why we recommend using the read-only 'svnlook' utility. 
  66.  
  67. #   In the future, Subversion may enforce the rule that pre-commit 
  68.  
  69. #   hooks should not modify the versioned data in txns, or else come 
  70.  
  71. #   up with a mechanism to make it safe to do so (by informing the 
  72.  
  73. #   committing client of the changes).  However, right now neither 
  74.  
  75. #   mechanism is implemented, so hook writers just have to be careful. 
  76.  
  77.  
  78. # Note that 'pre-commit' must be executable by the user(s) who will 
  79.  
  80. # invoke it (typically the user httpd runs as), and that user must 
  81.  
  82. # have filesystem-level permission to access the repository. 
  83.  
  84.  
  85. On a Windows system, you should name the hook program 
  86.  
  87. 'pre-commit.bat' or 'pre-commit.exe'
  88.  
  89. # but the basic idea is the same. 
  90.  
  91.  
  92. # The hook program typically does not inherit the environment of 
  93.  
  94. # its parent process.  For example, a common problem is for the 
  95.  
  96. # PATH environment variable to not be set to its usual value, so 
  97.  
  98. # that subprograms fail to launch unless invoked via absolute path. 
  99.  
  100. # If you're having unexpected problems with a hook program, the 
  101.  
  102. # culprit may be unusual (or missing) environment variables. 
  103.  
  104.  
  105. # Here is an example hook script, for a Unix /bin/sh interpreter. 
  106.  
  107. For more examples and pre-written hooks, see those in 
  108.  
  109. # the Subversion repository at 
  110.  
  111. # http://svn.apache.org/repos/asf/subversion/trunk/tools/hook-scripts/ and 
  112.  
  113. # http://svn.apache.org/repos/asf/subversion/trunk/contrib/hook-scripts/ 
  114.  
  115.   
  116.  
  117. REPOS="$1" 
  118.  
  119. TXN="$2" 
  120.  
  121. # Make sure that the log message contains some text. 
  122.  
  123. SVNLOOK=/usr/local/bin/svnlook 
  124.  
  125. SVNLOOKlog−t"TXN" "$REPOS" | \ 
  126.  
  127.    grep "[a-zA-Z0-9]" > /dev/null || exit 1 
  128.  
  129. Check that the author of this commit has the rights to perform 
  130.  
  131. # the commit on the files and directories being modified. 
  132.  
  133. commit-access-control.pl "REPOS""TXN" commit-access-control.cfg || exit 1 
  134.  
  135. All checks passed, so allow the commit
  136.  
  137. exit 0 
  1. 把pre-commit文件的内容清楚复制下面的代码到pre-commit文件中: 
  2.  
  3.   
  4.  
  5. @echo off 
  6.  
  7. setlocal 
  8.  
  9. set REPOS=%1 
  10.  
  11. set TXN=%2 
  12.  
  13. rem check that logmessage contains at least 10 characters 
  14.  
  15. rem .....代表5个字符 
  16.  
  17. svnlook log "%REPOS%" -t "%TXN%" | findstr ".........." > nul 
  18.  
  19. if %errorlevel% gtr 0 goto err 
  20.  
  21. exit 0 
  22.  
  23. :err 
  24.  
  25. echo Empty log message not allowed. Commit aborted! 1>&2 
  26.  
  27. exit 1 

2、给pre-commit添加可执行权限: chmod +x pre-commit

方式二、直接在客服端设置

通过TortoiseSvn,在本地副本中,选择项目,右键选择TortoiseSvn,选择属性,添加tsvn:logminsize,将值限定为10,添加了logminsize属性后,要将本地工作副本commit一下,才能生效。如下图:

效果图

 

责任编辑:武晓燕 来源: UP技术控
相关推荐

2010-05-26 17:26:36

SVN提交更新

2023-01-17 14:01:19

JavaScript类型转换字符串

2010-05-26 17:05:13

SVN提交

2010-05-26 17:13:54

SVN提交

2010-05-19 10:18:23

svn 403 for

2010-05-20 12:43:37

SVN Update命

2021-03-04 20:01:11

代码思考业务

2010-05-24 10:45:52

子命令Svn lock

2023-11-20 17:12:40

微软OpenAI

2010-05-24 14:16:34

子命令SVN diff

2010-05-20 17:06:48

SVN CO

2010-05-24 10:29:51

子命令Svn reve

2010-05-28 14:57:42

SVN-Importe

2010-06-02 13:36:18

SVN用法

2010-05-28 15:28:25

svn-importe

2022-09-23 10:12:14

SVN系统服务器

2010-05-24 12:53:38

子命令SVN merg

2010-05-31 19:02:17

访问SVN

2010-05-31 18:35:22

访问SVN

2010-05-25 10:24:42

设置SVN权限
点赞
收藏

51CTO技术栈公众号