Skip to content

Commit

Permalink
First attempt on symbolic references handling #328
Browse files Browse the repository at this point in the history
  • Loading branch information
ademarco committed Mar 14, 2017
1 parent e6b1846 commit 4f95d27
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/Task/Git/BranchName.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace GrumPHP\Task\Git;

use Gitonomy\Git\Exception\ProcessException;
use GrumPHP\Runner\TaskResult;
use GrumPHP\Task\Context\ContextInterface;
use GrumPHP\Task\Context\GitPreCommitContext;
Expand Down Expand Up @@ -63,12 +64,14 @@ public function getConfigurableOptions()
{
$resolver = new OptionsResolver();
$resolver->setDefaults([
'matchers' => [],
'additional_modifiers' => ''
'matchers' => [],
'additional_modifiers' => '',
'allow_symbolic_references' => true,
]);

$resolver->addAllowedTypes('matchers', ['array']);
$resolver->addAllowedTypes('additional_modifiers', ['string']);
$resolver->addAllowedTypes('allow_symbolic_references', ['boolean']);

return $resolver;
}
Expand Down Expand Up @@ -110,10 +113,18 @@ private function runMatcher(array $config, $name, $rule, $ruleName)
*/
public function run(ContextInterface $context)
{
$name = trim($this->repository->run('symbolic-ref', ['HEAD', '--short']));
$config = $this->getConfiguration();
$exceptions = [];

try {
$name = trim($this->repository->run('symbolic-ref', ['HEAD', '--short']));
} catch (ProcessException $e) {
if ($config['allow_symbolic_references'] === false) {
$message = "Branch naming convention task is not allowed to run on symbolic references.";
return TaskResult::createFailed($this, $context, $message);
}
}

foreach ($config['matchers'] as $ruleName => $rule) {
try {
$this->runMatcher($config, $name, $rule, $ruleName);
Expand Down

0 comments on commit 4f95d27

Please sign in to comment.