SVN Hooks 介绍
start-commit
参数
[1] REPOS-PATH (the path to this repository)
[2] USER (the authenticated user attempting to commit)
定制:暂时关闭提交功能
代码示例
#!/bin/sh
REPOS="$1"
USER="$2"
TOOLS_DIR=$REPOS/hooks/scripts
LOCK_FILE=$REPOS/hooks/COMMIT_LOCK
if [ -f $LOCK_FILE ]; then
if [ -s $LOCK_FILE ]; then
# Characters in LOCK_FILE should be utf-8 format!
cat $LOCK_FILE >&2
else
# echo "系统维护中,暂时禁止提交。" >&2
echo "Under maintenance, commit not allowed this time." >&2
fi
exit 1
fi
REPOS="$1"
USER="$2"
TOOLS_DIR=$REPOS/hooks/scripts
LOCK_FILE=$REPOS/hooks/COMMIT_LOCK
if [ -f $LOCK_FILE ]; then
if [ -s $LOCK_FILE ]; then
# Characters in LOCK_FILE should be utf-8 format!
cat $LOCK_FILE >&2
else
# echo "系统维护中,暂时禁止提交。" >&2
echo "Under maintenance, commit not allowed this time." >&2
fi
exit 1
fi
定制:检查 Repository 容量限制
代码示例
#!/bin/sh
# 参考: http://www.toutprogrammer.com/article_29_3.html
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:$PATH
REPOS="$1"
USER="$2"
MAX_SIZE=20480 # 20MB
repos_size=`du -s $REPOS | cut -f 1`
if [ $repos_size -gt $MAX_SIZE ]; then
echo "Repositroy $REPOS has exceeded maximum size: $MAX_SIZE" 1>&2
exit 1
fi
exit 0
# 参考: http://www.toutprogrammer.com/article_29_3.html
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:$PATH
REPOS="$1"
USER="$2"
MAX_SIZE=20480 # 20MB
repos_size=`du -s $REPOS | cut -f 1`
if [ $repos_size -gt $MAX_SIZE ]; then
echo "Repositroy $REPOS has exceeded maximum size: $MAX_SIZE" 1>&2
exit 1
fi
exit 0
pre-commit
参数
[1] REPOS-PATH (the path to this repository)
[2] TXN-NAME (the name of the txn about to be committed)
定制:检查 Commit Log 长度
bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:$PATH
REPOS="$1"
TXN="$2"
TOOLS_DIR=$REPOS/hooks/scripts
# Make sure that the log message contains some text.
SVNLOOK=/usr/local/bin/svnlook
commitlog=`$SVNLOOK log -t "$TXN" "$REPOS"`
case `echo -n ${commitlog}|wc -c` in
0)
echo "Commit log is blank, please write a comment for your commit." >&2
exit 1
;;
[1-2])
echo "Commit log must greater than 2 characters." >&2
exit 1
;;
*)
;;
esac
REPOS="$1"
TXN="$2"
TOOLS_DIR=$REPOS/hooks/scripts
# Make sure that the log message contains some text.
SVNLOOK=/usr/local/bin/svnlook
commitlog=`$SVNLOOK log -t "$TXN" "$REPOS"`
case `echo -n ${commitlog}|wc -c` in
0)
echo "Commit log is blank, please write a comment for your commit." >&2
exit 1
;;
[1-2])
echo "Commit log must greater than 2 characters." >&2
exit 1
;;
*)
;;
esac
python
def check_strlen(log_msg, minLen):
log_length = len(log_msg)
if log_length > 0:
char = log_msg[0]
char2= log_msg[-1]
idx=1
while idx < len(log_msg):
if char == -1 and char2 == -1 and log_length <= 0:
break
if (char == log_msg[idx]) and (char != -1):
log_length = log_length - 1
char = log_msg[idx]
else:
char = -1
if (char2 == log_msg[-idx]) and (char2 != -1):
log_length = log_length - 1
char2 = log_msg[-idx]
else:
char2 = -1
idx = idx + 1
if log_length < minLen:
sys.stderr.write ("Commit log must greater than %d characters, or too simple.\n" % minLen)
sys.exit(1)
log_length = len(log_msg)
if log_length > 0:
char = log_msg[0]
char2= log_msg[-1]
idx=1
while idx < len(log_msg):
if char == -1 and char2 == -1 and log_length <= 0:
break
if (char == log_msg[idx]) and (char != -1):
log_length = log_length - 1
char = log_msg[idx]
else:
char = -1
if (char2 == log_msg[-idx]) and (char2 != -1):
log_length = log_length - 1
char2 = log_msg[-idx]
else:
char2 = -1
idx = idx + 1
if log_length < minLen:
sys.stderr.write ("Commit log must greater than %d characters, or too simple.\n" % minLen)
sys.exit(1)
定制:检查用户权限
perl
配置文件 commit-access-control.cfg
示例
[Make everything read-only for all users]
match = .*
access = read-only
[Make project1 read-write for users Jane and Joe]
match = ^(branches|tags|trunk)/project1
users = jane joe
access = read-write
[However, we don't trust Joe with project1's Makefile]
match = ^(branches|tags|trunk)/project1/Makefile
users = joe
access = read-only
match = .*
access = read-only
[Make project1 read-write for users Jane and Joe]
match = ^(branches|tags|trunk)/project1
users = jane joe
access = read-write
[However, we don't trust Joe with project1's Makefile]
match = ^(branches|tags|trunk)/project1/Makefile
users = joe
access = read-only