Skip to content

Commit

Permalink
Using pre-add to replace the pre-commit hook
Browse files Browse the repository at this point in the history
  • Loading branch information
kayw-geek committed May 24, 2024
1 parent 6dedbe7 commit 541ae16
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Quality Hook Installer

Install an execute script of specify quality tools to your git pre-commit hook, and it executes only for changed files
Install an execute script of specify quality tools to your git pre-add hook, and it executes only for changed files
## Install

```BASH
Expand All @@ -12,18 +12,18 @@ composer global require kayw/quality-hook-installer
1. `quality run install --phpstan --php-cs-fixer`
2. Execute `git add .` in your project.
3. `git commit -m 'xxx'`
4. The pre-commit hook will be triggered and the PHPStan and PHPCsFixer will execute only for changed files.
4. The pre-add hook will be triggered and the PHPStan and PHPCsFixer will execute only for changed files.

## Commands

The following command will execute quality inspection only for changed files

`quality run --phpstan --php-cs-fixer`

The following command will write in your pre-commit of git hook
The following command will write in your pre-add of git hook

`quality run install --phpstan --php-cs-fixer`

The following command will remove your pre-commit of git hook
The following command will remove your pre-add of git hook

`quality run uninstall`
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "kayw/quality-hook-installer",
"description": "Install an execute script of specify quality tools to your git pre-commit hook, and it executes only for changed files",
"type": "project",
"type": "library",
"license": "MIT",
"autoload": {
"psr-4": {
Expand Down
8 changes: 4 additions & 4 deletions src/Command/RunCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ class RunCommand extends Command
protected function configure(): void
{
$this->setDescription('Put code quality inspection to git hook');
$this->setHelp('Install an execute script of specify quality tools to your git pre-commit hook, and it executes only for changed files');
$this->addArgument(self::ARGUMENT_INSTALL, InputArgument::OPTIONAL, 'Install a execute script of specify quality tools to your git per-commit hook');
$this->addArgument(self::ARGUMENT_UNINSTALL, InputArgument::OPTIONAL, 'Uninstall a execute script of specify quality tools to your git per-commit hook');
$this->setHelp('Install an execute script of specify quality tools to your git pre-add hook, and it executes only for changed files');
$this->addArgument(self::ARGUMENT_INSTALL, InputArgument::OPTIONAL, 'Install a execute script of specify quality tools to your git per-add hook');
$this->addArgument(self::ARGUMENT_UNINSTALL, InputArgument::OPTIONAL, 'Uninstall a execute script of specify quality tools to your git per-add hook');
$this->addOption(self::OPTION_PHPSTAN, '', InputOption::VALUE_NONE);
$this->addOption(self::OPTION_PHP_FIXER, '', InputOption::VALUE_NONE);
}
Expand Down Expand Up @@ -179,7 +179,7 @@ private function executeInstall(array $active_options, InputInterface $input, Ou
exec </dev/tty
eval "quality run $option_text"
EOF;
file_put_contents($this->getPath() . '/.git/hooks/pre-commit', $execute_command);
file_put_contents($this->getPath() . '/.git/hooks/pre-add', $execute_command);
$output->writeln('<info> The hook install success! </info>');

return self::SUCCESS;
Expand Down

0 comments on commit 541ae16

Please # to comment.