sweetchuck / robo-git

Git 相关的 Robo 任务

安装数: 109,137

依赖关系: 54

建议: 0

安全性: 0

星星: 3

关注者: 5

分支: 0

开放问题: 4

类型:robo-tasks

v0.3.0 2020-08-09 17:23 UTC

This package is auto-updated.

Last update: 2024-09-20 09:46:59 UTC


README

CircleCI codecov

与 ::taskExec() 相比,此任务的主要附加功能是解析 stdOutput/stdError 并通过将其放入属于管道的 \Robo\State\Data 实例来使结果可用于后续任务。

安装

运行 composer require --dev sweetchuck/robo-git

任务 - taskGitBranchList()

<?php

declare(strict_types = 1);

class RoboFileExample extends \Robo\Tasks
{
    use \Sweetchuck\Robo\Git\GitTaskLoader;

    public function gitBranches(string $dir = '.')
    {
        return $this
            ->collectionBuilder()
            ->addTask(
                $this
                    ->taskGitBranchList()
                    ->setWorkingDirectory($dir)
                    // Available options:
                    // --all
                    // --color
                    // --contains
                    // --format
                    // --list
                    // --merged
                    // --points-at
                    // --sort
            )
            ->addCode(function (\Robo\State\Data $data): int {
                // Here you can do whatever you want with the branches.
                $output = $this->output();
                foreach ($data['gitBranches'] as $longName => $branch) {
                    $output->writeln($longName);
                    foreach ($branch as $key => $value) {
                        $output->writeln("    $key = " . var_export($value, true));
                    }
                }

                return 0;
            });
    }
}

运行: $ vendor/bin/robo git:branches

示例输出

refs/heads/1.x
    isCurrentBranch = true
    push = 'refs/remotes/upstream/1.x'
    push.short = 'upstream/1.x'
    refName = 'refs/heads/1.x'
    refName.short = '1.x'
    track = ''
    track.ahead = NULL
    track.behind = NULL
    track.gone = false
    upstream = 'refs/remotes/upstream/1.x'
    upstream.short = 'upstream/1.x'

任务 - taskGitConfigGet()

<?php

declare(strict_types = 1);

class RoboFileExample extends \Robo\Tasks
{
    use \Sweetchuck\Robo\Git\GitTaskLoader;

    /**
     * @command git:config:get
     */
    public function gitConfigGet(string $name)
    {
        return $this
            ->collectionBuilder()
            ->addTask(
                $this
                    ->taskGitConfigGet()
                    ->setName($name)
            )
            ->addCode(function (\Robo\State\Data $data) use ($name): int {
                $key = "git.config.$name";
                $this->output()->writeln("$key = {$data[$key]}");

                return 0;
            });
    }
}

运行: $ vendor/bin/robo git:config:get

示例输出

git.config.user.name = Andor

任务 - taskGitCurrentBranch()

<?php

declare(strict_types = 1);

class RoboFileExample extends \Robo\Tasks
{
    use \Sweetchuck\Robo\Git\GitTaskLoader;

    /**
     * @command git:current-branch
     */
    public function gitCurrentBranch()
    {
        return $this
            ->collectionBuilder()
            ->addTask($this->taskGitCurrentBranch())
            ->addCode(function (\Robo\State\Data $data): int {
                $this->output()->writeln("long = {$data['gitCurrentBranch.long']}");
                $this->output()->writeln("short = {$data['gitCurrentBranch.short']}");

                return 0;
            });
    }
}

运行: $ vendor/bin/robo git:current-branch

示例输出

长名称 = refs/heads/1.x
短名称 = 1.x

任务 - taskGitListFiles()

<?php

declare(strict_types = 1);

class RoboFileExample extends \Robo\Tasks
{
    use \Sweetchuck\Robo\Git\GitTaskLoader;

    /**
     * @command git:list-files
     */
    public function gitListFiles()
    {
        return $this
            ->collectionBuilder()
            ->addTask(
                $this
                    ->taskGitListFiles()
                    ->setPaths(['R*.md'])
                    // Available options:
                    // -t
                    // -v
                    // -z
                    // --cached
                    // --deleted
                    // --directory
                    // --empty-directory
                    // --eol
                    // --exclude
                    // --exclude-file
                    // --full-name
                    // --killed
                    // --ignored
                    // --modified
                    // --others
                    // --stage
                    // --resolve-undo
                    // --unmerged
            )
            ->addCode(function (\Robo\State\Data $data): int {
                $output = $this->output();
                /** * @var \Sweetchuck\Robo\Git\ListFilesItem $file */
                foreach ($data['files'] as $filePath => $file) {
                    $output->writeln($filePath);
                    $output->writeln('    status = ' . var_export($file->status, true));
                    $output->writeln('    objectName = ' . var_export($file->objectName, true));
                    $output->writeln('    eolInfoI = ' . var_export($file->eolInfoI, true));
                    $output->writeln('    eolInfoW = ' . var_export($file->eolInfoW, true));
                    $output->writeln('    eolAttr = ' . var_export($file->eolAttr, true));
                    $output->writeln('    fileName = ' . var_export($file->fileName, true));
                }

                return 0;
            });
    }
}

运行: $ vendor/bin/robo git:list-files

示例输出

README.md
    status = NULL
    objectName = NULL
    eolInfoI = NULL
    eolInfoW = NULL
    eolAttr = NULL
    fileName = 'README.md'

任务 - taskGitListChangedFiles()

@todo

任务 - taskGitListStagedFiles()

@todo

任务 - taskGitNumOfCommitsBetween()

@todo

任务 - taskGitReadStagedFiles()

@todo

任务 - taskGitRemoteList()

@todo

任务 - taskGitStatus()

@todo

任务 - taskGitTagList()

@todo

任务 - taskGitTopLevel()

@todo