Skip to content

Commit

Permalink
up: update some for the git branch command match logic
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed May 24, 2022
1 parent f810026 commit 115ef50
Showing 1 changed file with 26 additions and 12 deletions.
38 changes: 26 additions & 12 deletions app/Console/Controller/Gitx/GitController.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
use function implode;
use function realpath;
use function sprintf;
use function str_contains;
use function strlen;
use function strpos;
use function strtolower;
Expand Down Expand Up @@ -112,9 +111,9 @@ protected static function commandAliases(): array
protected function getOptions(): array
{
return [
'--try,--dry-run' => 'bool;Dry-run the workflow, dont real execute',
'-y, --yes' => 'bool;Direct execution without confirmation',
'-w, --workdir' => 'The command work dir, default is current dir.',
'--try,--dry-run' => 'bool;Dry-run the workflow, dont real execute',
'-y, --yes' => 'bool;Direct execution without confirmation',
'-w, --workdir' => 'The command work dir, default is current dir.',
// '-i, --interactive' => 'Run in an interactive environment[TODO]',
];
}
Expand Down Expand Up @@ -202,6 +201,7 @@ public function updateCommand(FlagsParser $fs, Input $input, Output $output): vo
*
* @param FlagsParser $fs
* @param Output $output
*
* @example
* {binWithCmd} -- -u origin main # with custom args for call git push
*/
Expand Down Expand Up @@ -258,13 +258,12 @@ public function infoCommand(FlagsParser $fs, Output $output): void
* list branch by git branch
*
* @options
* -a, --all bool;Display all branches
* -r, --remote Display branches for the given remote
* --only-name bool;Only display branch name
* --inline bool;Only display branch name and print inline
* -s, --search The keyword name for search branches
*
* @arguments
* -a, --all bool;Display all branches
* -r, --remote Display branches for the given remote
* --on, --only-name bool;Only display branch name
* --inline bool;Only display branch name and print inline
* -s, --search The keyword name for search branches, allow multi by comma.
* Start with ^ for exclude.
*
* @param FlagsParser $fs
* @param Output $output
Expand All @@ -286,14 +285,22 @@ public function branchCommand(FlagsParser $fs, Output $output): void

$onlyName = $fs->getOpt('only-name');
$keyword = $fs->getOpt('search');
$keyword = strlen($keyword) > 1 ? $keyword : '';

$msg = 'Branch List';
if (strlen($remote) > 1) {
$msg .= " Of '$remote'";
}

$exclude = '';
if ($keyword) {
$msg .= "(keyword: $keyword)";
if ($keyword[0] === '^') {
$exclude = Str::splitTrimmed(substr($keyword, 1));
$keyword = '';
} else {
$keyword = Str::splitTrimmed($keyword);
}
}

$output->colored($msg . ':');
Expand All @@ -310,7 +317,14 @@ public function branchCommand(FlagsParser $fs, Output $output): void
$name = substr($name, $rmtLen);
}

if ($keyword && !str_contains($name, $keyword)) {
// 排除匹配
if ($exclude) {
if (Str::has($name, $exclude)) {
continue;
}

// 包含匹配搜索
} elseif ($keyword && !Str::has($name, $keyword)) {
continue;
}

Expand Down

0 comments on commit 115ef50

Please sign in to comment.