Ejemplo n.º 1
0
} else {
    define('VERBOSE', false);
}
$changed = false;
$source = __DIR__ . DS . 'git-hooks' . DS . PRE_COMMIT_HOOK;
$target = nZEDb_HOOKS . DS . PRE_COMMIT_HOOK;
if (!file_exists(nZEDb_HOOKS . PRE_COMMIT_HOOK)) {
    copy($source, $target);
}
$file = file($target, FILE_IGNORE_NEW_LINES);
if (preg_match('/^(?P<key>#version=)(?P<value>.*)$/', $file[1], $match)) {
    $current = $match['value'];
}
$out = new ColorCLI();
$versions = new \nzedb\utility\Versions();
$version = $versions->getGitHookPrecommit();
if ($version > $current) {
    copy($source, $target);
    echo $out->info("Updated pre-commit hook to version {$version}");
    $file = file($target, FILE_IGNORE_NEW_LINES);
}
chmod($target, 0774);
$count = count($file);
$index = 0;
while ($index < $count) {
    if (preg_match('/^#nZEDb hook\\s*-\\s*(.+)$/', $file[$index], $match)) {
        if (VERBOSE) {
            echo $out->primary("Matched: " . $file[$index]);
        }
        $index++;
        $file[$index] = trim($file[$index]);