前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Linux下svn提交时必须添加注释的设置

Linux下svn提交时必须添加注释的设置

原创
作者头像
知忆
修改2021-06-21 10:54:14
2.2K0
修改2021-06-21 10:54:14
举报
文章被收录于专栏:linux百科小宇宙linux百科小宇宙

如何在Linux系统下安装svn, 这里暂不介绍,请看本文下方的相关教程,在svn安装目录下有个hooks文件夹, 修改其中的pre-commit.tmpl文件;

cp pre-commit.tmpl pre-commit

修改pre-commit文件

#!/bin/sh

 

# PRE-COMMIT HOOK

#

# The pre-commit hook is invoked before a Subversion txn is

# committed.  Subversion runs this hook by invoking a program

# (script, executable, binary, etc.) named 'pre-commit' (for which

# this file is a template), with the following ordered arguments:

#

#   [1] REPOS-PATH   (the path to this repository)

#   [2] TXN-NAME     (the name of the txn about to be committed)

#

#   [STDIN] LOCK-TOKENS ** the lock tokens are passed via STDIN.

#

#   If STDIN contains the line "LOCK-TOKENS:\n" (the "\n" denotes a

#   single newline), the lines following it are the lock tokens fo

#   this commit.  The end of the list is marked by a line containing

#   only a newline character.

#

#   Each lock token line consists of a URI-escaped path, followed

#   by the separator character '|', followed by the lock token string,

#   followed by a newline.

#

# The default working directory for the invocation is undefined, so

# the program should set one explicitly if it cares.

#

# If the hook program exits with success, the txn is committed; but

# if it exits with failure (non-zero), the txn is aborted, no commit

# takes place, and STDERR is returned to the client.   The hook

# program can use the 'svnlook' utility to help it examine the txn.

#

# On a Unix system, the normal procedure is to have 'pre-commit'

# invoke other programs to do the real work, though it may do the

# work itself too.

#

#   ***  NOTE: THE HOOK PROGRAM MUST NOT MODIFY THE TXN, EXCEPT  ***

#   ***  FOR REVISION PROPERTIES (like svn:log or svn:author).   ***

#

#   This is why we recommend using the read-only 'svnlook' utility.

#   In the future, Subversion may enforce the rule that pre-commit

#   hooks should not modify the versioned data in txns, or else come

#   up with a mechanism to make it safe to do so (by informing the

#   committing client of the changes).  However, right now neithe

#   mechanism is implemented, so hook writers just have to be careful.

#

# Note that 'pre-commit' must be executable by the user(s) who will

# invoke it (typically the user httpd runs as), and that user must

# have filesystem-level permission to access the repository.

#

# On a Windows system, you should name the hook program

# 'pre-commit.bat' or 'pre-commit.exe',

# but the basic idea is the same.

#

# The hook program typically does not inherit the environment of

# its parent process.  For example, a common problem is for the

# PATH environment variable to not be set to its usual value, so

# that subprograms fail to launch unless invoked via absolute path.

# If you're having unexpected problems with a hook program, the

# culprit may be unusual (or missing) environment variables.

#

# Here is an example hook script, for a Unix /bin/sh interpreter.

# For more examples and pre-written hooks, see those in

# the Subversion repository at

# 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"

 

# Make sure that the log message contains some text.

SVNLOOK=/usr/bin/svnlook

 

# 添加以下5行代码

LOGMSG=`$SVNLOOK log -t "$TXN" "$REPOS" | grep "[a-zA-Z0-9]" | wc -c`

if [ "$LOGMSG" -lt 10 ];then 

   echo "提交失败: 注释不能低于10个字符" 1>&2 

   exit 1

fi

 

# 以下全部注释掉

# $SVNLOOK log -t "$TXN" "$REPOS" | \

#   grep "[a-zA-Z0-9]" > /dev/null || exit 1

 

# Check that the author of this commit has the rights to perform

# the commit on the files and directories being modified.

#commit-access-control.pl "$REPOS" "$TXN" commit-access-control.cfg || exit 1

 

# All checks passed, so allow the commit.

#exit 0

其实以上的去掉注释部分只有几行代码:

#!/bin/sh

 

REPOS="$1"

TXN="$2"

 

SVNLOOK=/usr/bin/svnlook  # 同pre-commit.tmpl文件中的SVNLOOK

LOGMSG=`$SVNLOOK log -t "$TXN" "$REPOS" | grep "[a-zA-Z0-9]" | wc -c`

if [ "$LOGMSG" -lt 10 ];then 

   echo "提交失败: 注释不能低于10个字符" 1>&2 

   exit 1

fi

然后 给pre-commit文件添加755权限:

chmod 755 pre-commit 或 chmod +x pre-commit

如果没有添加权限, 则会报:

Commit blocked by pre-commit hook (exit code 255) with no output 错误, 请注意。

更多Subversion (SVN)相关教程见以下内容

Ubuntu 14.04 下搭建SVN服务器 SVN://  http://www.linuxidc.com/Linux/2015-01/111956.htm

CentOS 7下安装iF.svnadmin实现Web方式管理SVN(源码安装)  http://www.linuxidc.com/Linux/2016-08/134214.htm

CentOS7.2 编译安装SVN1.9.5客户端  http://www.linuxidc.com/Linux/2017-03/141387.htm

SVN 服务器搭建步骤及使用实战 http://www.linuxidc.com/Linux/2017-01/139282.htm

CentOS 7下搭建配置SVN服务器  http://www.linuxidc.com/Linux/2017-05/144254.htm

CentOS 7.2下Nginx+MySQL+PHP-FPM+SVN配置Walle自动化部署系统详解 http://www.linuxidc.com/Linux/2016-11/137703.htm

基于腾讯CentOS 7云服务器搭建SVN版本控制库  http://www.linuxidc.com/Linux/2017-05/144244.htm

CentOS 7.1 下SVN安装与配置 http://www.linuxidc.com/Linux/2016-12/138637.htm

CentOS 6.8 搭建SVN(版本控制系统)及SVN的使用  http://www.linuxidc.com/Linux/2017-04/143093.htm

Linux上手动搭建svn服务器  http://www.linuxidc.com/Linux/2017-12/149777.htm

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
云数据库 MySQL
腾讯云数据库 MySQL(TencentDB for MySQL)为用户提供安全可靠,性能卓越、易于维护的企业级云数据库服务。其具备6大企业级特性,包括企业级定制内核、企业级高可用、企业级高可靠、企业级安全、企业级扩展以及企业级智能运维。通过使用腾讯云数据库 MySQL,可实现分钟级别的数据库部署、弹性扩展以及全自动化的运维管理,不仅经济实惠,而且稳定可靠,易于运维。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档