如何在SVN中设置post-commit脚本来更新修改后的文件?

时间:2016-11-09 08:37:08

标签: svn post-commit post-commit-hook

我删除了post-commit.tmpl,在post-commit文件中,这里是代码:

#!/bin/sh

export LANG=en_US.UTF-8   
SVN_Path=/root/svn/myblog
WEB_Path=/home/app/myblog
echo `date "+%Y-%m-%d %H:%M:%S"`
$SVN_Path update --username xxx --password yyy $WEB_Path --no-auth-cache 

# POST-COMMIT HOOK
#
# The post-commit hook is invoked after a commit.  Subversion runs
# this hook by invoking a program (script, executable, binary, etc.)
# named 'post-commit' (for which this file is a template) with the 
# following ordered arguments:
#
#   [1] REPOS-PATH   (the path to this repository)
#   [2] REV          (the number of the revision just committed)
#
# The default working directory for the invocation is undefined, so
# the program should set one explicitly if it cares.
#
# Because the commit has already completed and cannot be undone,
# the exit code of the hook program is ignored.  The hook program
# can use the 'svnlook' utility to help it examine the
# newly-committed tree.
#
# On a Unix system, the normal procedure is to have 'post-commit'
# invoke other programs to do the real work, though it may do the
# work itself too.
#
# Note that 'post-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
# 'post-commit.bat' or 'post-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"
# REV="$2"

# mailer.py commit "$REPOS" "$REV" /path/to/mailer.conf

不幸的是,在我将修改后的代码提交给服务器之后,我的项目文件(项目路径是/ home / app / myblog)中什么都不会发生。但是如果我在命令行中执行这个文件,我会得到这个信息:

 2016-11-09 16:32:10
./post-commit: line 9: /root/svn/myblog: Is a directory

同时,在以下路径中:/ root / svn / myblog / db / revprops / 0,我可以找到所有提交日志文件。我想这意味着修改后的文件被提交到服务器,对吗?

我正在使用CentOS,Express。

那么,有人可以帮我解决这个问题吗? THX !!

1 个答案:

答案 0 :(得分:0)

  

2016-11-09 16:32:10 ./post-commit: line 9: /root/svn/myblog: Is a directory

根据代码,$SVN_Path应指向Subversion命令行客户端svn。但它指向目录/myblog,而不是:

SVN_Path=/root/svn/myblog

您应该调整$SVN_Path以指向计算机上的svn客户端。

  

同时,在以下路径中:/ root / svn / myblog / db / revprops / 0,我可以   找到所有提交日志文件。我猜这意味着修改过的文件   致力于服务器,对吧?

提交后挂钩在提交后运行。所以,是的,提交进入了存储库。但是,由于$SVN_Path中的拼写错误,钩子没有运行。