diff --git a/app/Common/GitLocal/AbstractGitLocal.php b/app/Common/GitLocal/AbstractGitx.php similarity index 99% rename from app/Common/GitLocal/AbstractGitLocal.php rename to app/Common/GitLocal/AbstractGitx.php index 1143d69..4ebfe94 100644 --- a/app/Common/GitLocal/AbstractGitLocal.php +++ b/app/Common/GitLocal/AbstractGitx.php @@ -20,7 +20,7 @@ * * @package Inhere\Kite\Common\Git */ -abstract class AbstractGitLocal +abstract class AbstractGitx { public const GITHUB_HOST = 'https://github.com'; @@ -502,7 +502,7 @@ public function getWorkDir(): string /** * @param string $workDir * - * @return AbstractGitLocal + * @return AbstractGitx */ public function setWorkDir(string $workDir): self { diff --git a/app/Common/GitLocal/GitFactory.php b/app/Common/GitLocal/GitFactory.php index e73d55c..fdaf6ab 100644 --- a/app/Common/GitLocal/GitFactory.php +++ b/app/Common/GitLocal/GitFactory.php @@ -6,7 +6,7 @@ use PhpGit\Repo; /** - * class Gitflow + * class GitFactory * * @author inhere */ @@ -15,9 +15,9 @@ class GitFactory /** * @param string $repoDir * - * @return AbstractGitLocal + * @return AbstractGitx */ - public static function make(string $repoDir = ''): AbstractGitLocal + public static function make(string $repoDir = ''): AbstractGitx { $repo = Repo::new($repoDir); @@ -25,13 +25,13 @@ public static function make(string $repoDir = ''): AbstractGitLocal $configKey = $platform !== Repo::PLATFORM_CUSTOM ? $platform : 'git'; $settings = Kite::config()->getArray($configKey); - $typGit = match ($platform) { + $gx = match ($platform) { Repo::PLATFORM_GITHUB => new GitHub(null, $settings), Repo::PLATFORM_GITLAB => new GitLab(null, $settings), default => new GitLoc(null, $settings), }; - $typGit->setRepo($repo); - return $typGit; + $gx->setRepo($repo); + return $gx; } } diff --git a/app/Common/GitLocal/GitHub.php b/app/Common/GitLocal/GitHub.php index 1b4212b..530effb 100644 --- a/app/Common/GitLocal/GitHub.php +++ b/app/Common/GitLocal/GitHub.php @@ -9,7 +9,7 @@ * * @package Inhere\Kite\Common\Git */ -class GitHub extends AbstractGitLocal +class GitHub extends AbstractGitx { public const HOST = GitConst::GITHUB_HOST; public const GIT_HOST = GitConst::GITHUB_HOST; diff --git a/app/Common/GitLocal/GitLab.php b/app/Common/GitLocal/GitLab.php index 133743d..ce33498 100644 --- a/app/Common/GitLocal/GitLab.php +++ b/app/Common/GitLocal/GitLab.php @@ -9,7 +9,7 @@ * * @package Inhere\Kite\Common\Git */ -class GitLab extends AbstractGitLocal +class GitLab extends AbstractGitx { /** * @var string diff --git a/app/Common/GitLocal/GitLoc.php b/app/Common/GitLocal/GitLoc.php index a4d94fd..d4ed9ef 100644 --- a/app/Common/GitLocal/GitLoc.php +++ b/app/Common/GitLocal/GitLoc.php @@ -5,7 +5,7 @@ /** * class GitLoc */ -class GitLoc extends AbstractGitLocal +class GitLoc extends AbstractGitx { - + } \ No newline at end of file diff --git a/app/Console/Component/RedirectToGitGroup.php b/app/Console/Component/RedirectToGitGroup.php index 3c1f7bd..d7a1af9 100644 --- a/app/Console/Component/RedirectToGitGroup.php +++ b/app/Console/Component/RedirectToGitGroup.php @@ -3,7 +3,7 @@ namespace Inhere\Kite\Console\Component; use Inhere\Console\Controller; -use Inhere\Kite\Console\Controller\Gitx\GitController; +use Inhere\Kite\Console\Controller\Gitx\GitxController; use Inhere\Kite\Kite; use Throwable; use Toolkit\Cli\Cli; @@ -38,7 +38,7 @@ public function handle(Controller $ctrl, string $command, array $args): bool $app = $ctrl->getApp(); // resolve alias - $gitCtrl = $app->getController(GitController::getName()); + $gitCtrl = $app->getController(GitxController::getName()); $action = $gitCtrl->resolveAlias($command); $group = $ctrl->getRealGName(); diff --git a/app/Console/Controller/Gitx/GitHubController.php b/app/Console/Controller/Gitx/GitHubController.php index c257746..850c948 100644 --- a/app/Console/Controller/Gitx/GitHubController.php +++ b/app/Console/Controller/Gitx/GitHubController.php @@ -16,6 +16,7 @@ use Inhere\Kite\Common\CmdRunner; use Inhere\Kite\Common\GitLocal\GitHub; use Inhere\Kite\Console\Component\RedirectToGitGroup; +use Inhere\Kite\Console\SubCmd\Gitflow\UpdateNoPushCmd; use Inhere\Kite\Console\SubCmd\Gitflow\UpdatePushCmd; use Inhere\Kite\Helper\AppHelper; use Inhere\Kite\Kite; @@ -56,7 +57,8 @@ protected static function commandAliases(): array 'pr' => 'pullRequest', 'redirectList' => ['rl'], ], [ - UpdatePushCmd::getName() => UpdatePushCmd::aliases(), + UpdatePushCmd::getName() => UpdatePushCmd::aliases(), + UpdateNoPushCmd::getName() => UpdateNoPushCmd::aliases(), ]); } @@ -67,6 +69,7 @@ protected function subCommands(): array { return [ UpdatePushCmd::class, + UpdateNoPushCmd::class, ]; } @@ -77,7 +80,7 @@ protected function getOptions(): array { return [ '--try,--dry-run' => 'bool;Dry-run the workflow, dont real execute', - '-w, --workdir' => 'The command work dir, default is current dir.', + '-w, --workdir' => 'The command work dir, default is current dir.', // '-y, --yes' => 'Direct execution without confirmation', // '-i, --interactive' => 'Run in an interactive environment[TODO]', ]; @@ -103,7 +106,7 @@ protected function beforeRun(): void /** * @param string $command - * @param array $args + * @param array $args * * @return bool * @throws Throwable @@ -124,7 +127,7 @@ protected function onNotFound(string $command, array $args): bool /** * Show a list of commands that will be redirected to git * - * @param Input $input + * @param Input $input * @param Output $output */ public function redirectListCommand(Input $input, Output $output): void @@ -147,7 +150,7 @@ public function redirectListCommand(Input $input, Output $output): void * --last Use the latest tag for new release * --next Auto calc next version for new release * - * @param Input $input + * @param Input $input * @param Output $output * * @example @@ -269,7 +272,7 @@ public function cloneCommand(FlagsParser $fs, Output $output): void $repo = $fs->getArg('repo'); $name = $fs->getArg('name'); - $mirror = $fs->getOpt('mirror'); + $mirror = $fs->getOpt('mirror'); $mirrors = [ 'fast' => 'https://hub.fastgit.org', 'cnpmjs' => 'https://github.com.cnpmjs.org', diff --git a/app/Console/Controller/Gitx/GitLabController.php b/app/Console/Controller/Gitx/GitLabController.php index 9354e83..cec73f3 100644 --- a/app/Console/Controller/Gitx/GitLabController.php +++ b/app/Console/Controller/Gitx/GitLabController.php @@ -23,6 +23,8 @@ use Inhere\Kite\Console\Attach\Gitlab\ProjectCmd; use Inhere\Kite\Console\Component\RedirectToGitGroup; use Inhere\Kite\Console\SubCmd\Gitflow\BranchCreateCmd; +use Inhere\Kite\Console\SubCmd\Gitflow\UpdateNoPushCmd; +use Inhere\Kite\Console\SubCmd\Gitflow\UpdatePushCmd; use Inhere\Kite\Console\SubCmd\GitlabCmd\ResolveConflictCmd; use Inhere\Kite\Helper\AppHelper; use Inhere\Kite\Kite; @@ -66,21 +68,24 @@ public static function aliases(): array protected static function commandAliases(): array { return [ - 'deleteBranch' => ['del-br', 'delbr', 'dbr', 'db'], - 'newBranch' => ['new-br', 'newbr', 'nbr', 'nb'], - 'li' => 'linkInfo', - 'cf' => 'config', - 'conf' => 'config', - 'rc' => 'resolve', - 'new' => 'create', - 'up' => 'update', - 'updatePush' => ['upp', 'up-push'], - 'project' => ['pj', 'info'], - 'checkout' => ['co'], - 'branch' => BranchCmd::aliases(), - MergeRequestCmd::getName() => MergeRequestCmd::aliases(), - ResolveConflictCmd::getName() => ResolveConflictCmd::aliases(), - ]; + 'deleteBranch' => ['del-br', 'delbr', 'dbr', 'db'], + 'newBranch' => ['new-br', 'newbr', 'nbr', 'nb'], + 'li' => 'linkInfo', + 'cf' => 'config', + 'conf' => 'config', + 'rc' => 'resolve', + 'new' => 'create', + 'up' => 'update', + 'updatePush' => ['upp', 'up-push'], + 'project' => ['pj', 'info'], + 'checkout' => ['co'], + ] + [ + BranchCmd::getName() => BranchCmd::aliases(), + MergeRequestCmd::getName() => MergeRequestCmd::aliases(), + ResolveConflictCmd::getName() => ResolveConflictCmd::aliases(), + UpdatePushCmd::getName() => UpdatePushCmd::aliases(), + UpdateNoPushCmd::getName() => UpdateNoPushCmd::aliases(), + ]; } /** @@ -93,6 +98,8 @@ protected function subCommands(): array ProjectCmd::class, MergeRequestCmd::class, ResolveConflictCmd::class, + UpdatePushCmd::class, + UpdateNoPushCmd::class, ]; } @@ -469,6 +476,7 @@ public function projectCommand(FlagsParser $fs, Output $output): void * * @param FlagsParser $fs * @param Output $output + * * @example * {binWithCmd} group/repo */ @@ -488,7 +496,7 @@ public function openCommand(FlagsParser $fs, Output $output): void if (str_starts_with($remote, 'http')) { $link = $remote; } else { - $link = $gitlab->getHost() . '/'. $remote; + $link = $gitlab->getHost() . '/' . $remote; } } else { $info = $gitlab->getRemoteInfo($remote); @@ -654,39 +662,6 @@ public function createCommand(FlagsParser $fs, Output $output): void $output->success("Create the '$name' ok!"); } - /** - * update codes from origin and main remote repository, then push to remote - * - * @param Output $output - * - * @throws Throwable - */ - public function updatePushCommand(Output $output): void - { - // $args = $this->flags->getRawArgs(); - // // add option - do push - // $args[] = '--push'; - // - // // run updateCommand(); - // $this->runActionWithArgs('update', $args); - - $this->runUpdateByGit(true, $output); - } - - /** - * update codes from origin and main remote repositories - * - * @options - * -p, --push bool;Push to origin remote after update - * - * @param FlagsParser $fs - * @param Output $output - */ - public function updateCommand(FlagsParser $fs, Output $output): void - { - $this->runUpdateByGit($fs->getOpt('push'), $output); - } - /** * @param bool $doPush * @param Output $output diff --git a/app/Console/Controller/Gitx/GitController.php b/app/Console/Controller/Gitx/GitxController.php similarity index 99% rename from app/Console/Controller/Gitx/GitController.php rename to app/Console/Controller/Gitx/GitxController.php index 1a956ce..93a6e29 100644 --- a/app/Console/Controller/Gitx/GitController.php +++ b/app/Console/Controller/Gitx/GitxController.php @@ -48,11 +48,9 @@ use function trim; /** - * Class GitController - * - git:tag:push add tag and push to remote - * - git:tag:delete delete the tag on remote + * Class GitxController */ -class GitController extends Controller +class GitxController extends Controller { protected static string $name = 'git'; diff --git a/app/Console/SubCmd/Gitflow/UpdateNoPushCmd.php b/app/Console/SubCmd/Gitflow/UpdateNoPushCmd.php new file mode 100644 index 0000000..81c9e07 --- /dev/null +++ b/app/Console/SubCmd/Gitflow/UpdateNoPushCmd.php @@ -0,0 +1,54 @@ +flags->addOptByRule($name, $rule); + } + + /** + * update codes from origin and main remote repository, then push to remote + * + * @options + * --dr, --dry-run bool;Dry-run the workflow, dont real execute + * --rb, --remote-branch The remote branch name, default is current branch name. + * + * @param Input $input + * @param Output $output + * + * @return int + * @throws Throwable + */ + protected function execute(Input $input, Output $output): int + { + $flags = $this->flags->getFlags(); + $flags[] = '--np'; + + $upCmd = new UpdatePushCmd($input, $output); + $upCmd->run($flags); + + return 0; + } +} diff --git a/app/Console/SubCmd/Gitflow/UpdatePushCmd.php b/app/Console/SubCmd/Gitflow/UpdatePushCmd.php index d044a6e..14b03c7 100644 --- a/app/Console/SubCmd/Gitflow/UpdatePushCmd.php +++ b/app/Console/SubCmd/Gitflow/UpdatePushCmd.php @@ -45,25 +45,29 @@ protected function configFlags(FlagsParser $fs): void */ protected function execute(Input $input, Output $output): mixed { - $typGit = GitFactory::make(); + $fs = $this->flags; + $gx = GitFactory::make(); - $curBranch = $typGit->getCurBranch(); - $upBranch = $this->flags->getOpt('remote-branch', $curBranch); + $curBranch = $gx->getCurBranch(); + $upBranch = $fs->getOpt('remote-branch', $curBranch); $output->info("Current Branch: $curBranch, fetch remote branch: $upBranch"); $runner = CmdRunner::new(); - $runner->setDryRun($this->flags->getOpt('dry-run')); + $runner->setDryRun($fs->getOpt('dry-run')); $runner->add('git pull'); - $runner->addf('git pull %s %s', $typGit->getMainRemote(), $upBranch); + $runner->addf('git pull %s %s', $gx->getMainRemote(), $upBranch); - $defBranch = $typGit->getDefaultBranch(); + $defBranch = $gx->getDefaultBranch(); if ($upBranch !== $defBranch) { - $runner->addf('git pull %s %s', $typGit->getMainRemote(), $defBranch); + $runner->addf('git pull %s %s', $gx->getMainRemote(), $defBranch); } - $si = $typGit->getStatusInfo(); + $si = $gx->getStatusInfo(); + + if (!$fs->getOpt('not-push')) { + $runner->addf('git push %s', $si->upRemote); + } - $runner->addf('git push %s', $si->upRemote); $runner->run(true); $output->success('Complete. datetime: ' . date('Y-m-d H:i:s'));