-
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.
👔 up: update some git and gitlab commands logic
- Loading branch information
Showing
6 changed files
with
150 additions
and
8 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
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
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
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
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,79 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Inhere\Kite\Console\SubCmd\GitxCmd; | ||
|
||
use Inhere\Console\Command; | ||
use Inhere\Console\IO\Input; | ||
use Inhere\Console\IO\Output; | ||
use Inhere\Kite\Common\Cmd; | ||
use Toolkit\FsUtil\Dir; | ||
use Toolkit\PFlag\FlagsParser; | ||
use Toolkit\Stdlib\Str; | ||
|
||
/** | ||
* Class BatchRunCmd | ||
*/ | ||
class BatchRunCmd extends Command | ||
{ | ||
protected static string $name = 'run'; | ||
protected static string $desc = 'batch run custom command on multi repository dir'; | ||
|
||
public static function aliases(): array | ||
{ | ||
return ['exec']; | ||
} | ||
|
||
protected function configFlags(FlagsParser $fs): void | ||
{ | ||
// $this->flags->addOptByRule($name, $rule); | ||
} | ||
|
||
/** | ||
* @options | ||
* -i, --include Include match filter | ||
* -e, --exclude Exclude match filter | ||
* -c, --cmd Exec the command on each git repo dir | ||
* Built in vars: | ||
* {dir} current dir path. | ||
* {d_name} current dir name. | ||
* {p_dir} parent dir path.;true | ||
* @arguments | ||
* dirs... array;The parent dir for multi git repository;required | ||
* | ||
* @param Input $input | ||
* @param Output $output | ||
* | ||
* @return int | ||
* @example | ||
* {cmdPath} -c 'pwd' ../ | ||
* {cmdPath} -c 'git status' ../ | ||
* {cmdPath} -c 'echo {d_name}' ../ | ||
* {cmdPath} -c 'kite git log 3' ../ | ||
*/ | ||
protected function execute(Input $input, Output $output): int | ||
{ | ||
$fs = $this->flags; | ||
$cmd = $fs->getOpt('cmd'); | ||
$dirs = $fs->getArg('dirs'); | ||
|
||
foreach ($dirs as $dir) { | ||
$output->colored("In the parent dir: " . $dir); | ||
$vars = [ | ||
'p_dir' => $dir, | ||
]; | ||
|
||
foreach (Dir::getDirs($dir) as $subDir) { | ||
$repoDir = Dir::join($dir, $subDir); | ||
|
||
$output->colored("- In the git repo dir: " . $repoDir); | ||
$vars['dir'] = $repoDir; | ||
$vars['d_name'] = $subDir; | ||
|
||
$cmdline = Str::renderVars($cmd, $vars, '{%s}'); | ||
Cmd::new('', $repoDir)->setCmdline($cmdline)->runAndPrint(); | ||
} | ||
} | ||
|
||
return 0; | ||
} | ||
} |
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,63 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Inhere\Kite\Console\SubCmd\GitxCmd; | ||
|
||
use Inhere\Console\Command; | ||
use Inhere\Console\IO\Input; | ||
use Inhere\Console\IO\Output; | ||
use PhpGit\Repo; | ||
|
||
/** | ||
* class BranchCleanCmd | ||
* | ||
* @author inhere | ||
* @date 2023/1/9 | ||
*/ | ||
class BranchCleanCmd extends Command | ||
{ | ||
protected static string $name = 'clean'; | ||
protected static string $desc = 'quickly clean git branches by input conditions'; | ||
|
||
public static function aliases(): array | ||
{ | ||
return ['clear', 'clr']; | ||
} | ||
|
||
/** | ||
* @options | ||
* -a, --all bool;Display branches for all remote and local | ||
* -r, --remote Both delete local and remote branches | ||
* -s, --search The keywords for search branches, allow multi by comma. | ||
* Start with ^ for exclude. | ||
* --m, --match The branch name search match, support var and regex. | ||
* eg: fix_{ymd}, fix_{ymd}*, fix_[\d]{6}. | ||
* --cond, --condition The condition for clean handle logic. | ||
* eg: $ymd < 180Day | ||
* | ||
* @param Input $input | ||
* @param Output $output | ||
* @example | ||
* {binWithCmd} -m fix_{ymd} --cond '$ymd < 180Day' | ||
*/ | ||
protected function execute(Input $input, Output $output): void | ||
{ | ||
$fs = $this->flags; | ||
$opts = []; | ||
$repo = Repo::new(); | ||
|
||
$remote = ''; | ||
$search = $fs->getOpt('search'); | ||
|
||
if ($fs->getOpt('all')) { | ||
$opts['all'] = true; | ||
} elseif ($remote = $fs->getOpt('remote')) { | ||
$opts['remotes'] = true; | ||
} | ||
|
||
$list = $repo->getGit()->branch->getList($opts, $search); | ||
|
||
foreach ($list as $item) { | ||
$output->println("branch: {$item['name']}"); | ||
} | ||
} | ||
} |