From 625ed1bfa6fc70716736be303b1f7a048b894756 Mon Sep 17 00:00:00 2001 From: Marco Cesarato Date: Mon, 18 Jan 2021 19:25:08 +0100 Subject: [PATCH] feat: add amend and no verify options --- src/Changelog.php | 9 ++++++++- src/DefaultCommand.php | 2 ++ src/Git.php | 11 +++++++++-- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/Changelog.php b/src/Changelog.php index 84e7fc6..32a8c12 100644 --- a/src/Changelog.php +++ b/src/Changelog.php @@ -32,6 +32,8 @@ public function generate(InputInterface $input, SymfonyStyle $output) $root = $input->getArgument('path'); // Root $autoCommit = $input->getOption('commit'); // Commit once changelog is generated + $amend = $input->getOption('amend'); // Amend commit + $hooks = !$input->getOption('no-verify'); // Verify git hooks $fromDate = $input->getOption('from-date'); $toDate = $input->getOption('to-date'); $history = $input->getOption('history'); @@ -52,6 +54,11 @@ public function generate(InputInterface $input, SymfonyStyle $output) unset($this->config->types['refactor']); } + // If have amend option enable commit + if ($amend) { + $autoCommit = true; + } + // Initialize changelogs $file = $root . DIRECTORY_SEPARATOR . $this->config->getFileName(); $changelogCurrent = ''; @@ -243,7 +250,7 @@ public function generate(InputInterface $input, SymfonyStyle $output) // Create commit and add tag if ($autoCommit) { - Git::commit("chore(release): {$newVersion}", [$file]); + Git::commit("chore(release): {$newVersion}", [$file], $amend, $hooks); Git::tag('v' . $newVersion); $output->success("Committed new version with tag: v{$newVersion}"); diff --git a/src/DefaultCommand.php b/src/DefaultCommand.php index cd87cc1..e5042de 100644 --- a/src/DefaultCommand.php +++ b/src/DefaultCommand.php @@ -49,6 +49,7 @@ protected function configure() ->setDefinition([ new InputArgument('path', InputArgument::OPTIONAL, 'Define the path directory where generate changelog', getcwd()), new InputOption('commit', 'c', InputOption::VALUE_NONE, 'Commit the new release once changelog is generated'), + new InputOption('amend', null, InputOption::VALUE_NONE, 'Amend commit the new release once changelog is generated'), new InputOption('first-release', null, InputOption::VALUE_NONE, 'Run at first release (if --ver isn\'t specified version code it will be 1.0.0)'), new InputOption('from-date', null, InputOption::VALUE_REQUIRED, 'Get commits from specified date [YYYY-MM-DD]'), new InputOption('to-date', null, InputOption::VALUE_REQUIRED, 'Get commits last tag date (or specified on --from-date) to specified date [YYYY-MM-DD]'), @@ -59,6 +60,7 @@ protected function configure() new InputOption('history', null, InputOption::VALUE_NONE, 'Generate the entire history of changes of all releases'), new InputOption('no-chores', null, InputOption::VALUE_NONE, 'Exclude chores type from changelog'), new InputOption('no-refactor', null, InputOption::VALUE_NONE, 'Exclude refactor type from changelog'), + new InputOption('no-verify', null, InputOption::VALUE_NONE, 'Bypasses the pre-commit and commit-msg hooks'), ]); } diff --git a/src/Git.php b/src/Git.php index 4b73330..05d4b4c 100644 --- a/src/Git.php +++ b/src/Git.php @@ -115,13 +115,20 @@ public static function getTags() * @param $message * @param $files */ - public static function commit($message, $files = []) + public static function commit($message, $files = [], $amend = false, $verify = true) { foreach ($files as $file) { system("git add \"{$file}\""); } $message = str_replace('"', "'", $message); // Escape - system("git commit -m \"{$message}\""); + $command = "git commit -m \"{$message}\""; + if ($amend) { + $command .= ' --amend'; + } + if (!$verify) { + $command .= ' --no-verify'; + } + system($command); } /**