Skip to content

Commit

Permalink
perf(git): update some git command logic
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Dec 16, 2021
1 parent 10b4460 commit 34e298a
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 25 deletions.
4 changes: 2 additions & 2 deletions app/Common/GitLocal/AbstractGitLocal.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ abstract class AbstractGitLocal
public const GITHUB_HOST = 'https://github.com';

/**
* @var Repo
* @var Repo|null
*/
protected Repo $repo;
protected ?Repo $repo = null;

/**
* @var string
Expand Down
60 changes: 38 additions & 22 deletions app/Console/Controller/GitLabController.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static function aliases(): array
protected static function commandAliases(): array
{
return [
'pullRequest' => ['pr', 'mr'],
'pullRequest' => ['pr', 'mr', 'merge-request'],
'deleteBranch' => ['del-br', 'delbr', 'dbr', 'db'],
'newBranch' => ['new-br', 'newbr', 'nbr', 'nb'],
'li' => 'linkInfo',
Expand Down Expand Up @@ -582,6 +582,11 @@ public function resolveCommand(FlagsParser $fs, Output $output): void
*
* @param FlagsParser $fs
* @param Output $output
* @help
* Special:
* `@`, HEAD - Current branch.
* `@s` - Source branch.
* `@t` - Target branch.
*
* @example
* {binWithCmd} Will generate PR link for fork 'HEAD_BRANCH' to main 'HEAD_BRANCH'
Expand Down Expand Up @@ -622,8 +627,14 @@ public function pullRequestCommand(FlagsParser $fs, Output $output): void

$open = $fs->getOpt('open');
// if input '@', 'head', use current branch name.
if ($open && ($open === '@' || strtoupper($open) === 'HEAD')) {
$open = $curBranch;
if ($open) {
if ($open === '@' || strtoupper($open) === 'HEAD') {
$open = $curBranch;
} elseif ($open === '@s') {
$open = $srcBranch;
} elseif ($open === '@t') {
$open = $tgtBranch;
}
}

// if ($tgtBranch) {
Expand Down Expand Up @@ -852,27 +863,21 @@ public function createCommand(FlagsParser $fs, Output $output): void
}

/**
* update codes from origin and main remote repositories, then push to remote
* update codes from origin and main remote repository, then push to remote
*
* @param Output $output
* @throws Throwable
*/
public function updatePushCommand(): void
public function updatePushCommand(Output $output): void
{
// $input->setSOpt('p', true);
// $this->updateCommand($input, $output);

/*
args:
array(3) {
[0]=> string(2) "updatePush"
}
*/
$args = $this->flags->getRawArgs();
// add option - do push
$args[] = '--push';

// run updateCommand();
$this->runActionWithArgs('update', $args);
// $args = $this->flags->getRawArgs();
// // add option - do push
// $args[] = '--push';
//
// // run updateCommand();
// $this->runActionWithArgs('update', $args);

$this->runUpdateByGit(true, $output);
}

/**
Expand All @@ -885,6 +890,17 @@ public function updatePushCommand(): void
* @param Output $output
*/
public function updateCommand(FlagsParser $fs, Output $output): void
{
$this->runUpdateByGit($fs->getOpt('push'), $output);
}

/**
* @param bool $doPush
* @param Output $output
*
* @return void
*/
protected function runUpdateByGit(bool $doPush, Output $output): void
{
$gitlab = $this->getGitlab();

Expand All @@ -900,8 +916,8 @@ public function updateCommand(FlagsParser $fs, Output $output): void
$runner->addf('git pull %s master', $gitlab->getMainRemote());
}

if ($fs->getOpt('push')) {
$runner->add('git push');
if ($doPush) {
$runner->add('git push origin');
}

$runner->run(true);
Expand Down
File renamed without changes.
File renamed without changes.
11 changes: 11 additions & 0 deletions script/shtests/list-subdir.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

usrKiteDir=~/.kite

#for dir in $(ls $usrKiteDir/vendor) ; do
for dir in $usrKiteDir/vendor ; do
if [ -d "$dir"]; then
continue
fi
echo $dir
done
13 changes: 13 additions & 0 deletions script/update-kite-deps-by-cp.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env sh

# run: sh script/update-kite-deps-by-cp.sh
set -ex

tmpKiteDir=~/Workspace/my-github/inhere/kite
usrKiteDir=~/.kite

cpDeps="cebe clue colinodell gitonomy guzzlehttp http-interop knplabs nette php-http monolog psr symfony"
for dir in $cpDeps ; do
rm -rf $usrKiteDir/vendor/$dir
cp -r $tmpKiteDir/vendor/$dir $usrKiteDir/vendor/
done
9 changes: 8 additions & 1 deletion script/update-kite-deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,11 @@ cd $tmpKiteDir || exit 2
composer update

cp $tmpKiteDir/composer.lock $usrKiteDir
cp -r $tmpKiteDir/vendor/composer $usrKiteDir/vendor/composer
rm -rf $usrKiteDir/vendor/composer
cp -r $tmpKiteDir/vendor/composer $usrKiteDir/vendor

cpDeps="cebe clue colinodell gitonomy guzzlehttp http-interop knplabs nette php-http monolog psr symfony"
for dir in $cpDeps ; do
rm -rf $usrKiteDir/vendor/$dir
cp -r $tmpKiteDir/vendor/$dir $usrKiteDir/vendor/
done
File renamed without changes.

0 comments on commit 34e298a

Please sign in to comment.