ausi/remote-git

远程编辑git仓库

资助包维护!
ausi

0.2.5 2023-10-31 22:59 UTC

This package is auto-updated.

Last update: 2024-09-15 18:19:30 UTC


README

Build Status Coverage Packagist Version Downloads MIT License

此库提供了远程处理git仓库的方法,无需克隆整个仓库。它使用Symfony进程组件来运行git客户端。

用法

<?php
use Ausi\RemoteGit\Repository;
use Ausi\RemoteGit\GitObject\File;
use Ausi\RemoteGit\Exception\ConnectionException;
use Ausi\RemoteGit\Exception\PushCommitException;

$repo = new Repository('ssh://git@github.com/ausi/remote-git.git');

try {
    $repo->connect();
} catch(ConnectionException $exception) {
    // Unable to connect to the specified server
}

$headCommit = $repo->getBranch('main')->getCommit();

$newTree = $headCommit
    ->getTree()
    ->withFile(
        'example.txt',
        'Example content…',
    )
;

$newCommit = $repo->commitTree($newTree, 'Add example', $headCommit);

try {
    $repo->pushCommit($newCommit, 'main');
} catch(PushCommitException $exception) {
    // Unable to push to the specified remote, e.g. no write access
}

安装

要安装此库,请使用Composer或从GitHub下载源代码文件。

composer require ausi/remote-git

速度

克隆https://gitlab.com/linux-kernel/stable.git并与读取文件内容的速度比较

当然,这强烈依赖于许多因素,如带宽和CPU功率,只能提供一个大致的项目目的概念,即从或向远程GIT仓库读取或写入小块数据。