diff --git a/app/Console/Controller/Gitx/GitController.php b/app/Console/Controller/Gitx/GitController.php index 4d41063..1a956ce 100644 --- a/app/Console/Controller/Gitx/GitController.php +++ b/app/Console/Controller/Gitx/GitController.php @@ -19,6 +19,7 @@ use Inhere\Kite\Console\Component\Clipboard; use Inhere\Kite\Console\Manager\GitBranchManager; use Inhere\Kite\Console\SubCmd\BranchCmd; +use Inhere\Kite\Console\SubCmd\GitTagCmd; use Inhere\Kite\Helper\AppHelper; use Inhere\Kite\Helper\GitUtil; use Inhere\Kite\Kite; @@ -97,7 +98,6 @@ protected static function commandAliases(): array 'tp', 'tag-push', ], - 'tagList' => ['tag', 'tags', 'tl', 'taglist'], 'tagInfo' => ['tag-info', 'ti', 'tag-show'], ]; } @@ -109,6 +109,7 @@ protected function subCommands(): array { return [ BranchCmd::class, + GitTagCmd::class, ]; } @@ -427,29 +428,6 @@ public function tagFindCommand(FlagsParser $fs, Input $input, Output $output): v $output->printf($title, $tagName); } - /** - * list all git tags for the project - * - * @arguments - * keywords Filter by input keywords - * - * @param FlagsParser $fs - * @param Output $output - */ - public function tagListCommand(FlagsParser $fs, Output $output): void - { - // git tag --sort=-creatordate 倒序排列 - $cmd = 'git tag -l -n2'; - $kw = $fs->getArg(0); - if ($kw) { - $cmd .= " | grep $kw"; - } - - CmdRunner::new($cmd)->do(true); - - $output->success('Complete'); - } - /** * display git tag information by `git show TAG` * @@ -477,6 +455,7 @@ public function tagInfoCommand(FlagsParser $fs, Output $output): void * @options * -v, --version The new tag version. e.g: v2.0.4 * -m, --message The message for add new tag. + * --hash The hash ID for add new tag. default is HEAD * -n, --next bool;Auto calc next version for add new tag. * --no-auto-add-v bool;Not auto add 'v' for add tag version. * @@ -510,6 +489,9 @@ public function tagNewCommand(FlagsParser $fs, Input $input, Output $output): vo return; } + $hashId = $fs->getOpt('hash'); + $dryRun = $this->flags->getOpt('dry-run'); + // $remotes = Git::new($dir)->remote->getList(); if ($tag[0] !== 'v' && !$fs->getOpt('no-auto-add-v')) { $tag = 'v' . $tag; @@ -517,7 +499,8 @@ public function tagNewCommand(FlagsParser $fs, Input $input, Output $output): vo $info = [ 'Work Dir' => $dir, - // 'Origin' => $remotes, + 'Hash ID' => $hashId, + 'Dry Run' => $dryRun, 'New Tag' => $tag, ]; @@ -527,9 +510,9 @@ public function tagNewCommand(FlagsParser $fs, Input $input, Output $output): vo $msg = $fs->getOpt('message'); $msg = $msg ?: "Release $tag"; + // add message $info['Message'] = $msg; - $output->aList($info, 'Information', ['ucFirst' => false]); if ( @@ -541,14 +524,12 @@ public function tagNewCommand(FlagsParser $fs, Input $input, Output $output): vo return; } - $dryRun = $this->flags->getOpt('dry-run'); - // git tag -a $1 -m "Release $1" // git push origin --tags // $cmd = sprintf('git tag -a %s -m "%s" && git push origin %s', $tag, $msg, $tag); $run = CmdRunner::new(); $run->setDryRun($dryRun); - $run->addf('git tag -a %s -m "%s"', $tag, $msg); + $run->addf('git tag -a %s -m "%s" %s', $tag, $msg, $hashId); $run->addf('git push origin %s', $tag); $run->runAndPrint(); diff --git a/app/Console/SubCmd/GitTagCmd.php b/app/Console/SubCmd/GitTagCmd.php new file mode 100644 index 0000000..c727680 --- /dev/null +++ b/app/Console/SubCmd/GitTagCmd.php @@ -0,0 +1,41 @@ +run($this->flags->getFlags()); + } +} diff --git a/app/Console/SubCmd/GitxCmd/GitTagListCmd.php b/app/Console/SubCmd/GitxCmd/GitTagListCmd.php new file mode 100644 index 0000000..a5e9035 --- /dev/null +++ b/app/Console/SubCmd/GitxCmd/GitTagListCmd.php @@ -0,0 +1,41 @@ +flags; + + // git tag --sort=-creatordate 倒序排列 + $cmd = 'git tag -l -n2'; + $kw = $fs->getArg(0); + if ($kw) { + $cmd .= " | grep $kw"; + } + + CmdRunner::new($cmd)->do(true); + + $output->success('Complete'); + } +}