-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add new git op command and some consts
- Loading branch information
Showing
2 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Inhere\Kite\Common\GitLocal; | ||
|
||
/** | ||
* class GitConst | ||
* | ||
* @author inhere | ||
* @date 2022/10/28 | ||
*/ | ||
class GitConst | ||
{ | ||
public const GITHUB_HOST = 'https://github.com'; | ||
public const GITHUB_GIT = 'git@github.com'; | ||
|
||
/** | ||
* remote url host type | ||
*/ | ||
public const HOST_TYPE_GH = 'github'; | ||
public const HOST_TYPE_GL = 'gitlab'; | ||
public const HOST_TYPE_LOC = 'gitloc'; | ||
|
||
public const ALLOW_HOST_TYPES = [ | ||
self::HOST_TYPE_GH, | ||
self::HOST_TYPE_GL, | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Inhere\Kite\Console\SubCmd\Gitflow; | ||
|
||
use Inhere\Console\Command; | ||
use Inhere\Console\IO\Input; | ||
use Inhere\Console\IO\Output; | ||
use Inhere\Kite\Common\CmdRunner; | ||
use Inhere\Kite\Common\GitLocal\GitFactory; | ||
use Toolkit\PFlag\FlagsParser; | ||
use function date; | ||
|
||
/** | ||
* Class UpdatePushCmd | ||
* | ||
* @package Inhere\Kite\Console\Controller\Gitlab | ||
*/ | ||
class UpdatePushCmd extends Command | ||
{ | ||
protected static string $name = 'up-push'; | ||
protected static string $desc = 'quick delete git branches from local, origin, main remote'; | ||
|
||
public static function aliases(): array | ||
{ | ||
return ['upp']; | ||
} | ||
|
||
protected function configFlags(FlagsParser $fs): void | ||
{ | ||
// $this->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; | ||
} | ||
} |