Skip to content
This repository was archived by the owner on Dec 8, 2017. It is now read-only.

Commit 8222d02

Browse files
author
Samuel Parkinson
committed
Add option to install a hook outside of the source folder.
1 parent 960b458 commit 8222d02

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

hooks/example-pre-commit.php

100644100755
File mode changed.

src/Command/HookInstallCommand.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,24 @@ protected function configure()
2727

2828
$this->setDescription('Symlink a hook to the given target.');
2929

30-
$this->addArgument('hook', InputArgument::REQUIRED, 'The hook to link.')
30+
$this->addArgument('hook', InputArgument::REQUIRED, 'The hook to link, either a path to a file or the filename of a hook in the hooks folder.')
3131
->addArgument('target', InputArgument::REQUIRED, 'The target location, including the filename (e.g. .git/hooks/pre-commit).');
3232

3333
$this->addOption('force', 'f', InputOption::VALUE_NONE, 'Overrite any existing files at the symlink target.');
3434
}
3535

3636
protected function execute(InputInterface $input, OutputInterface $output)
3737
{
38-
$hooksPath = realpath(__DIR__ . '/../../hooks/');
38+
$source = realpath(__DIR__ . '/../../hooks/') . '/' . $input->getArgument('hook') . '.php';
39+
40+
if (! file_exists($source) && file_exists($input->getArgument('hook'))) {
41+
$source = $input->getArgument('hook');
42+
} else {
43+
$error = sprintf('<error>The hook %s does not exist!</error>', $input->getArgument('hook'));
44+
$output->writeln($error);
45+
exit(1);
46+
}
3947

40-
$source = $hooksPath . '/' . $input->getArgument('hook') . '.php';
4148
$target = $input->getArgument('target');
4249
$force = $input->getOption('force');
4350

0 commit comments

Comments
 (0)