Skip to content

Commit

Permalink
Make hooker able to deal with undefined hook types
Browse files Browse the repository at this point in the history
Also add list of known hook types
  • Loading branch information
bigtallbill committed Mar 10, 2015
1 parent 6816a83 commit 8f7dfd1
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/Bigtallbill/Hooker/Hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public function process($argv, array $config, $type)
if ($result !== true) {
return $result;
}

$result = $this->executeAfter($argv, $config, $type);
if ($result !== true) {
return $result;
Expand Down
27 changes: 27 additions & 0 deletions src/Bigtallbill/Hooker/HookUnknown.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
/**
* Created by PhpStorm.
* User: bigtallbill
* Date: 3/9/15
* Time: 9:01 PM
*/

namespace Bigtallbill\Hooker;


class HookUnknown extends Hook {

/**
* @param array $argv
*
* @param array $config
*
* @param string $type The commit hook type
*
* @return bool True if the hook passes checks False if any errors are encountered
*/
public function execute($argv, array $config, $type)
{
return true;
}
}
25 changes: 22 additions & 3 deletions src/Bigtallbill/Hooker/Hooker.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,21 @@ class Hooker
protected $hooks = array(
'pre-commit',
'commit-msg',
'pre-push'
'pre-push',
'applypatch-msg',
'pre-applypatch',
'post-applypatch',
'prepare-commit-msg',
'post-commit',
'pre-rebase',
'post-checkout',
'post-merge',
'pre-receive',
'update',
'post-receive',
'post-update',
'pre-auto-gc',
'post-rewrite'
);

/** @var string The currently executing script */
Expand Down Expand Up @@ -147,8 +161,13 @@ public function execute($type, $argv)
{
$class = "Bigtallbill\\Hooker\\" . $this->transformHookNameToClass($type);

/** @var Hook $hook */
$hook = new $class;
if (!class_exists($class)) {
$hook = new HookUnknown();
} else {
/** @var Hook $hook */
$hook = new $class;
}

return $hook->process($argv, $this->loadedConfig, $type);
}

Expand Down

0 comments on commit 8f7dfd1

Please sign in to comment.