Move git-hooks out of newznab into build folder, update hooks, remove addGitHook.php, not used anymore (ported from nZEDb @niel)

This commit is contained in:
DariusIII
2015-12-09 10:40:40 +01:00
parent 4e1f3ac31c
commit 7bc41f386f
5 changed files with 32 additions and 117 deletions
+2
View File
@@ -1,3 +1,5 @@
2015-12-09 DariusIII
Chg: Move git-hooks out of newznab into build folder, update hooks, remove addGitHook.php, not used anymore (ported from nZEDb @niel)
2015-12-08 DariusIII
Fix: Try to fix failing query when lastArticleDate is NULL (fix @kevin123)
Fix: Missing / from path to covers in movie.tpl
+17
View File
@@ -0,0 +1,17 @@
#!/usr/bin/env bash
NNTMUX=`pwd`
HOOKS=/build/git-hooks
GIT=/.git/hooks
PC=/pre-commit
NNTMUX=${NNTMUX%${HOOKS}}
echo "${NNTMUX}${GIT}"
if [ -x "${NNTMUX}${GIT}${PC}" ]
then
rm "${NNTMUX}${GIT}${PC}"
echo .
fi
ln -s ${NNTMUX}${HOOKS}${PC} ${NNTMUX}${GIT}${PC}
+12 -6
View File
@@ -1,5 +1,5 @@
#!/bin/sh
#version=9
#version=10
#
# The hook should
# exit with non-zero status after issuing an appropriate message if
@@ -18,8 +18,15 @@ fi
#####################################################################################################
EXIT_STATUS=0
PROJECT=/path/to/newznab/
HOOKS=${PROJECT}newznab/build/git-hooks
NNTMUX=`pwd`
HOOK_DIR=/build/git-hooks
GIT=/.git/hooks
PC=/pre-commit
# Strip off the current directory path if we are run from in the git-hooks directory.
PROJECT=${NNTMUX%${HOOK_DIR}}
HOOKS=${PROJECT}${HOOK_DIR}
FILE_LIST=${HOOKS}/git_hook_list.txt
if [ -e ${FILE_LIST} ]
@@ -33,8 +40,7 @@ do
echo ${PROJECT}/${FILE} >> ${FILE_LIST}
done
#newznab hook - run hooks
# placeholder for script to add command with correct path ;-)
/usr/bin/php ${HOOKS}/runHooks.php
EXIT_STATUS=$?
@@ -49,4 +55,4 @@ then
fi
# If there are whitespace errors, print the offending file names and fail.
exec git diff-index --check --cached ${AGAINST} --
exec git diff-index --check --cached ${AGAINST} --
+1 -1
View File
@@ -20,7 +20,7 @@
*/
define('GIT_PRE_COMMIT', true);
require_once realpath(dirname(dirname(dirname(__DIR__))) . DIRECTORY_SEPARATOR . 'indexer.php');
require_once realpath(dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR . 'indexer.php');
use newznab\db\DbUpdate;
use newznab\utility\Git;
-110
View File
@@ -1,110 +0,0 @@
<?php
/**
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program (see LICENSE.txt in the base directory. If
* not, see:
*
* @link <http://www.gnu.org/licenses/>.
* @author niel
* @copyright 2014 nZEDb
*/
require_once realpath(dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR . 'indexer.php');
use newznab\ColorCLI;
define('NN_GIT', NN_ROOT . '.git' . DS);
define('NN_HOOKS', NN_GIT . 'hooks' . DS);
define('PRE_COMMIT_HOOK', 'pre-commit');
define('GIT_HOOK_VERSION', 2);
$current = 1;
if ($argc > 1 && $argv[1]) {
define('VERBOSE', true);
} else {
define('VERBOSE', false);
}
$changed = false;
$source = __DIR__ . DS . 'git-hooks' . DS . PRE_COMMIT_HOOK;
$target = NN_HOOKS . DS . PRE_COMMIT_HOOK;
if (!file_exists(NN_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 \newznab\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('/^#newznab hook\s*-\s*(.+)$/', $file[$index], $match)) {
if (VERBOSE) {
echo $out->primary("Matched: " . $file[$index]);
}
$index++;
$file[$index] = trim($file[$index]);
switch ($match[1]) {
case 'update version info':
case 'run hooks':
$hook = '/usr/bin/php ' . NN_LIB . 'build/git-hooks/runHooks.php';
if ($hook != $file[$index]) {
if (VERBOSE) {
echo $out->primary('Replace: "' . $file[$index] . '" with "' . $hook . '"');
}
$file[$index] = $hook;
$changed = true;
} else {
echo $out->primary("Skipped: " . $file[$index]);
}
break;
default:
$index--;
echo $out->error('Invalid hook placeholder!!');
break;
}
} else if (preg_match('#^PROJECT=(?P<path>.*)$#', $file[$index], $match)) {
if ($match['path'] != NN_ROOT) {
$file[$index] = 'PROJECT=' . NN_ROOT;
$changed = true;
}
} else {
if (VERBOSE) {
echo $out->primary("Skipped: " . $file[$index]);
}
}
$index++;
}
if ($changed === false) {
echo $out->warning('Unable to find any hooks needing updates!');
} else {
if (file_put_contents($target, implode("\n", $file)) === false) {
echo $out->error("Error writing file to disc!!");
}
}