我正在尝试编写一个 SVN 提交后钩子,但奇怪的是,我却在本应最简单的部分上遇到了困难。
剧本:
#!/usr/bin/sh
set REPO="$1"
set REV="$2"
set SVNBIN="/opt/CollabNet_Subversion/bin/"
set SSHBIN="/usr/bin/ssh"
set HOST="staging.domain.net"
set timeout=30
set USERNAME="svn-usr"
set E_NO_CONNECT=2
set E_WRONG_PASS=3
set E_UNKOWN=25
set CHANGED=`"$SVNBIN"svnlook changed --revision $REV $REPOS`
echo "Here are changes: $CHANGED" >> /var/svn/repos/www/logs/testing
echo "Command: $0; Repo: $REPO; Rev: $REV; Total: $#" >> /var/svn/repos/www/logs/testing
set PROJECT ""
然而,当我调用它时,它似乎没有看到我传递给它的参数:
/var/svn/repos/www/logs> sudo ../hooks/post-commit /var/svn/repos/www 33
svnlook: missing argument: --revision
Type 'svnlook help' for usage.
/var/svn/repos/www/logs> cat testing
Here are changes:
Command: ../hooks/post-commit; Repo: ; Rev: ; Total: 1
这是在 Solaris 10 SPARC 盒子上。
我对脚本有点陌生,但这不是很容易吗?
答案1
set
它并没有按照您想象的那样做:它修改了位置参数$1
、、$2
......$@
等等。它没有分配变量。
set REPO="$1"
set REV="$2"
应该:
REPO="$1"
REV="$2"
(ETC)
答案2
我不确定你为什么有所有这些set
命令,删除它们并看看是否有效?
答案3
REPO="$1"
REV="$2"
SVNBIN="/opt/CollabNet_Subversion/bin/"
SSHBIN="/usr/bin/ssh"
HOST="staging.domain.net"
timeout=30
USERNAME="svn-usr"
E_NO_CONNECT=2
E_WRONG_PASS=3
E_UNKOWN=25
CHANGED=`"$SVNBIN"svnlook changed --revision $REV $REPOS`
.....
PROJECT=""