From 7bc41f386f4bb4aeba46872d9c3caffe8f22d7eb Mon Sep 17 00:00:00 2001 From: DariusIII Date: Wed, 9 Dec 2015 10:40:40 +0100 Subject: [PATCH] Move git-hooks out of newznab into build folder, update hooks, remove addGitHook.php, not used anymore (ported from nZEDb @niel) --- Changelog | 2 + build/git-hooks/addHooks.sh | 17 +++ {newznab/build => build}/git-hooks/pre-commit | 18 ++- .../build => build}/git-hooks/runHooks.php | 2 +- newznab/build/addGitHook.php | 110 ------------------ 5 files changed, 32 insertions(+), 117 deletions(-) create mode 100755 build/git-hooks/addHooks.sh rename {newznab/build => build}/git-hooks/pre-commit (74%) mode change 100644 => 100755 rename {newznab/build => build}/git-hooks/runHooks.php (95%) mode change 100644 => 100755 delete mode 100644 newznab/build/addGitHook.php diff --git a/Changelog b/Changelog index 5533b6ee9..d76fd197d 100755 --- a/Changelog +++ b/Changelog @@ -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 diff --git a/build/git-hooks/addHooks.sh b/build/git-hooks/addHooks.sh new file mode 100755 index 000000000..50ea8cbed --- /dev/null +++ b/build/git-hooks/addHooks.sh @@ -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} diff --git a/newznab/build/git-hooks/pre-commit b/build/git-hooks/pre-commit old mode 100644 new mode 100755 similarity index 74% rename from newznab/build/git-hooks/pre-commit rename to build/git-hooks/pre-commit index d0d320d80..e2c8ab3ba --- a/newznab/build/git-hooks/pre-commit +++ b/build/git-hooks/pre-commit @@ -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} -- \ No newline at end of file +exec git diff-index --check --cached ${AGAINST} -- diff --git a/newznab/build/git-hooks/runHooks.php b/build/git-hooks/runHooks.php old mode 100644 new mode 100755 similarity index 95% rename from newznab/build/git-hooks/runHooks.php rename to build/git-hooks/runHooks.php index f472c0e5e..c378ba82e --- a/newznab/build/git-hooks/runHooks.php +++ b/build/git-hooks/runHooks.php @@ -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; diff --git a/newznab/build/addGitHook.php b/newznab/build/addGitHook.php deleted file mode 100644 index d23999b01..000000000 --- a/newznab/build/addGitHook.php +++ /dev/null @@ -1,110 +0,0 @@ -. - * @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#version=)(?P.*)$/', $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.*)$#', $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!!"); - } -}