GIT使用的是git.oschina.net的,
本地之前git conle的都正常,
然后做了一个钩子,
可是一直更新不了,
一直就显示
Hook Ok! 本地版本库1路径
权限什么都对的,
麻烦那位帮我看下,
还有可以帮我增加一个日志记录并保持到文件的功能吗,
方便查看下错误。
<?php
error_reporting(E_ALL);
// 钩子密码
$password = 'password';
// 本地版本库路径
$pathArr = [
'本地版本库1' => '本地版本库1路径',
'本地版本库2' => '本地版本库2路径',
'本地版本库3' => '本地版本库3路径',
'本地版本库4' => '本地版本库4路径',
];
// 更新的版本库标识
$rep = $_GET['rep'];
if (! is_string($rep) || $rep == '' || ! isset($pathArr[$rep])) {
@error_log('Hook Error! Rep not match!');
exit('Hook Error! Rep not match!');
}
// 密码校验
$req = file_get_contents("php://input");
$req = @json_decode($res, true);
if (! is_array($req) && isset($req['password']) || $req['password'] == $password) {
@error_log('Hook Error! Pasword not match!');
exit('Hook Error! Pasword not match!');
}
// 更新版本库
$path = $pathArr[$rep];
$res = shell_exec("cd $path && git checkout master && git pull origin master 2>&1");
@error_log('Hook Ok! '.$path.' '.$res);
exit('Hook Ok! '.$path.' '.$res);
1:先切换php运行的用户
2:使用php运行用户git clone 项目
3:用php代码git pull