我創建了一個Subversion掛鉤,它執行各種操作,包括髮送電子郵件和更新服務器上的工作副本。當它從bash propt運行時,它可以很好地工作。在提交時通過TortoiseSVN或Netbeans運行時,會發送電子郵件等,但不會執行更新,也不會顯示任何錯誤。該文件是一個PHP文件,我使用反引號方法來運行bash命令。運行其他bash命令來編寫電子郵件,所以這不是問題。Subversion Hook不會在運行時自動運行'svn update',但會在bash提示符下運行
下面是應該運行更新並記錄結果的行。 $位置是從工作副本位置的數據庫中提取的。
$update_output = `/usr/local/bin/svn update /home/$location >> update.log`;
由於
詹姆斯
編輯,更完整的腳本:
#!/usr/local/bin/php
<?
$REPOS = $argv[1];
$REV = $argv[2];
$output[] = `/usr/local/bin/svnlook dirs-changed -r $REV $REPOS`;
foreach($output as $line)
{
preg_match("$([^/]+)$", $line, $array);
$projects[] = $array[0];
}
$projects = array_unique($projects);
$mysqli = new mysqli('localhost', 'svn_user', 'pringles', 'svn_maindb');
if ($mysqli->connect_error) {
die('Connect Error (' . $mysqli->connect_errno . ') '
. $mysqli->connect_error);
}
foreach($projects as $project)
{
$query = "SELECT * FROM Project WHERE name = '$project' LIMIT 1";
$result = $mysqli->query($query);
$row = $result->fetch_assoc();
$proj_id = $row['id'];
$location = $row['location'];
if(!empty($location))
{
$update_output = `/usr/local/bin/svn update /home/$location >> update.log`;
}
/* The below line only works when the script is run by hand */
$test = `/usr/bin/lessecho test >> /home/svn/repo/hooks/update.log`;
/* Grab user from DB and call send_email for user */
}
function send_email($REPOS, $REV, $programmer, $email)
{
$author = `/usr/local/bin/svnlook author -r $REV $REPOS`;
$message .= "Project Committed By $author
Comments:
";
$message .= `/usr/local/bin/svnlook log -r $REV $REPOS`;
$message .= "
===========List of Changes========
U = Updated
A = Added
D = Deleted
";
$message .= `/usr/local/bin/svnlook changed -r $REV $REPOS`;
/* Compose and Send Email */
}
什麼用戶SVN運行的?這是因爲權限嗎? – ircmaxell 2010-12-21 15:40:53
我不確定,它可以運行svnlook,現在我已經用svn命令的完整路徑替換了svn。我怎麼能找出它正在運行的用戶? – jaz9090 2010-12-21 17:03:30
如果您有權訪問命令行,請運行`ps aux | grep svnserve` ... – ircmaxell 2010-12-21 17:05:53