From e738b29b22cbdaa1cd1490408cff3b1b4299a2f2 Mon Sep 17 00:00:00 2001 From: Tomasz Kisiel Date: Sun, 2 Jan 2022 01:04:33 +0100 Subject: [PATCH] feat: annotated tags --- src/Changelog.php | 3 ++- src/DefaultCommand.php | 1 + src/Git/Repository.php | 13 ++++++++----- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/Changelog.php b/src/Changelog.php index df61bba..564c81d 100644 --- a/src/Changelog.php +++ b/src/Changelog.php @@ -53,6 +53,7 @@ public function generate(string $root, InputInterface $input, SymfonyStyle $outp $autoCommit = $input->getOption('commit'); // Commit once changelog is generated $autoCommitAll = $input->getOption('commit-all'); // Commit all changes once changelog is generated $autoTag = !($input->getOption('no-tag') || $this->config->skipTag()); // Tag release once is committed + $annotateTag = $input->getOption('annotate-tag'); $amend = $input->getOption('amend'); // Amend commit $hooks = !$input->getOption('no-verify'); // Verify git hooks $hooks = $hooks && $this->config->skipVerify() ? false : true; @@ -419,7 +420,7 @@ public function generate(string $root, InputInterface $input, SymfonyStyle $outp // Create tag if ($autoTag) { $tag = $tagPrefix . $newVersion . $tagSuffix; - $result = Repository::tag($tag); + $result = Repository::tag($tag, $annotateTag); if ($result !== false) { $output->success("Release tagged with success! New version: {$tag}"); } else { diff --git a/src/DefaultCommand.php b/src/DefaultCommand.php index 12f0f4a..208bb66 100644 --- a/src/DefaultCommand.php +++ b/src/DefaultCommand.php @@ -83,6 +83,7 @@ protected function configure() new InputOption('history', null, InputOption::VALUE_NONE, 'Generate the entire history of changes of all releases'), new InputOption('no-verify', null, InputOption::VALUE_NONE, 'Bypasses the pre-commit and commit-msg hooks'), new InputOption('no-tag', null, InputOption::VALUE_NONE, 'Disable release auto tagging'), + new InputOption('annotate-tag', null, InputOption::VALUE_OPTIONAL, 'Make an unsigned, annotated tag object once changelog is generated', false), new InputOption('merged', null, InputOption::VALUE_NONE, 'Only include commits whose tips are reachable from HEAD.'), ]); } diff --git a/src/Git/Repository.php b/src/Git/Repository.php index 8b7e09f..2e2718e 100644 --- a/src/Git/Repository.php +++ b/src/Git/Repository.php @@ -57,8 +57,8 @@ public static function getLastCommit(): string public static function getLastTag($merged = false, $prefix = ''): string { $merged = ($merged) ? '--merged' : ''; - - return self::run("git for-each-ref 'refs/tags/". $prefix . "*' --sort=-v:refname --format='%(refname:strip=2)' --count=1 {$merged}"); + + return self::run("git for-each-ref 'refs/tags/" . $prefix . "*' --sort=-v:refname --format='%(refname:strip=2)' --count=1 {$merged}"); } /** @@ -145,7 +145,7 @@ public static function getCommits(string $options = ''): array */ public static function getTags($prefix = ''): array { - $tags = self::run("git tag '". $prefix . "*' --sort=-v:refname --list --format='%(refname:strip=2)" . self::$delimiter . "'") . "\n"; + $tags = self::run("git tag '" . $prefix . "*' --sort=-v:refname --list --format='%(refname:strip=2)" . self::$delimiter . "'") . "\n"; $tagsArray = explode(self::$delimiter . "\n", $tags); array_pop($tagsArray); @@ -205,9 +205,12 @@ public static function commit(string $message, array $files = [], bool $amend = * * @return string */ - public static function tag(string $name) + public static function tag(string $name, $annotation = false) { - return exec("git tag {$name}"); + $message = $annotation ?: $name; + $flags = $annotation !== false ? "-a -m {$message}" : ''; + + return exec("git tag {$flags} {$name}"); } /**