gitee 添加webhook

GIT服务器配置一个能访问的url的php文件

让后给gitee 配置 url

进行本地上传测试

报错1:

atal: detected dubious ownership in repository at ‘/www/wwwroot/hyperf’
To add an exception for this directory, call:
git config –global –add safe.directory /www/wwwroot/hyperf
运行
git config –global –add safe.directory /www/wwwroot/hyperf

 

 

钩子文件

<?php

$fs = fopen('./git_hook.log', 'a');
fwrite($fs, 'Request on [' . date("Y-m-d H:i:s") . ']' . PHP_EOL);
//$json = file_get_contents('php://input');
//$data = json_decode($json, true);
//  fwrite($fs, 'Data: '.print_r($data, true).PHP_EOL);
//$user = shell_exec("whoami"); //服务器上先把shell_exec和exec函数禁用解除
//输出服务器执行git pull 的用户是谁
// fwrite($fs, print_r($user, true).PHP_EOL);
//仓库地址
$name = urlencode('XXX@qq.com');
$pass = urlencode('XXX@qq.com');
// $remote = "http://XXX%40qq.com:XXX%40qq.com@11.3.0.31:8099/test/test.git";
$remote = "https://{$name}:{$pass}@gitee.com/liusongs/tp6.git"; //自己git仓库,加上用户名密码防止没有权限
// usr/bin/git  checkout. 报错了
// $res = shell_exec("cd /www/wwwroot/tp6 && /usr/bin/git  checkout. && /usr/bin/git pull {$remote} 2>&1");
// $res = shell_exec("cd /www/wwwroot/tp6 && /usr/bin/git pull {$remote} 2>&1");
//换成 /usr/bin/git reset --hard   彻底回退到某个版本,本地的源码也会变为上一个版本的内容,撤销的commit中所包含的更改被冲掉;
$res = shell_exec("cd /www/wwwroot/tp6 && /usr/bin/git reset --hard && /usr/bin/git pull  {$remote} 2>&1");

// $res = shell_exec("cd /www/wwwroot/tp6 && git pull 2>&1");
fwrite($fs, '执行完成$res:' . print_r($res, true) . PHP_EOL);
// var_dump($res);
fwrite($fs, '===============================================================' . PHP_EOL);
fclose($fs);
//     fwrite($fs,$res.'$res'.PHP_EOL);
exit;

 

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注