Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
131 views
in Technique[技术] by (71.8m points)

GIT PHP钩子无法成功执行

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);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

1:先切换php运行的用户
2:使用php运行用户git clone 项目
3:用php代码git pull


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...