From ae5f053287020f4f8aaa98a26d56aa4b3aa65bf2 Mon Sep 17 00:00:00 2001 From: Inhere Date: Fri, 28 Oct 2022 13:38:37 +0800 Subject: [PATCH] feat: add new git op command and some consts --- app/Common/GitLocal/GitConst.php | 27 ++++++++ app/Console/SubCmd/Gitflow/UpdatePushCmd.php | 72 ++++++++++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 app/Common/GitLocal/GitConst.php create mode 100644 app/Console/SubCmd/Gitflow/UpdatePushCmd.php diff --git a/app/Common/GitLocal/GitConst.php b/app/Common/GitLocal/GitConst.php new file mode 100644 index 0000000..1e2ba6b --- /dev/null +++ b/app/Common/GitLocal/GitConst.php @@ -0,0 +1,27 @@ +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 + * --np, --not-push bool;Not push to remote repo after updated. + * --rb, --remote-branch The remote branch name, default is current branch name. + * + * @param Input $input + * @param Output $output + * + * @return mixed + */ + protected function execute(Input $input, Output $output): mixed + { + $typGit = GitFactory::make(); + + $curBranch = $typGit->getCurBranch(); + $upBranch = $this->flags->getOpt('remote-branch', $curBranch); + $output->info("Current Branch: $curBranch, fetch remote branch: $upBranch"); + + $runner = CmdRunner::new(); + $runner->setDryRun($this->flags->getOpt('dry-run')); + $runner->add('git pull'); + $runner->addf('git pull %s %s', $typGit->getMainRemote(), $upBranch); + + $defBranch = $typGit->getDefaultBranch(); + if ($upBranch !== $defBranch) { + $runner->addf('git pull %s %s', $typGit->getMainRemote(), $defBranch); + } + + $si = $typGit->getStatusInfo(); + + $runner->addf('git push %s', $si->upRemote); + $runner->run(true); + + $output->success('Complete. datetime: ' . date('Y-m-d H:i:s')); + return 0; + } +}