diff --git a/README.md b/README.md index 00de7ba..c2574a5 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Quality Hook Installer -Install an execute script of specify quality tools to your git pre-add hook, and it executes only for changed files +Install an execute script of specify quality tools to your git pre-commit hook, and it executes only for changed files ## Install ```BASH @@ -12,7 +12,7 @@ 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-add hook will be triggered and the PHPStan and PHPCsFixer will execute only for changed files. +4. The pre-commit hook will be triggered and the PHPStan and PHPCsFixer will execute only for changed files. ## Commands @@ -20,10 +20,10 @@ 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-add of git hook +The following command will write in your pre-commit of git hook `quality run install --phpstan --php-cs-fixer` -The following command will remove your pre-add of git hook +The following command will remove your pre-commit of git hook `quality run uninstall` diff --git a/src/Command/RunCommand.php b/src/Command/RunCommand.php index e2d4c81..b48e45e 100644 --- a/src/Command/RunCommand.php +++ b/src/Command/RunCommand.php @@ -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-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->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->addOption(self::OPTION_PHPSTAN, '', InputOption::VALUE_NONE); $this->addOption(self::OPTION_PHP_FIXER, '', InputOption::VALUE_NONE); } @@ -69,7 +69,7 @@ private function checkPhpCsFixerConfigFileExist(): bool private static function getChangedFilesString(): ?string { - exec('git diff --name-only --diff-filter=M', $exec_output); + exec('git diff --name-only HEAD --diff-filter=M', $exec_output); return implode(' ', $exec_output); } @@ -179,7 +179,7 @@ private function executeInstall(array $active_options, InputInterface $input, Ou exec getPath() . '/.git/hooks/pre-add', $execute_command); + file_put_contents($this->getPath() . '/.git/hooks/pre-commit', $execute_command); $output->writeln(' The hook install success! '); return self::SUCCESS;