lotharthesavior / branch
用于操作 Git 仓库的 PHP 库。基于 coyl/Git.php 及其分支
2.0.0
2022-10-31 03:54 UTC
Requires
- php: ^8.1
Requires (Dev)
- mockery/mockery: ^1.2
- phpunit/phpunit: ^9.5
README
分支
Branch 是一个基于 kbjr/Git.php 的 PHP Git 库
描述
Branch 是一个 PHP Git 仓库控制库。允许从 PHP 类中运行任何 git 命令。使用 proc_open
运行 git 命令,而不是 exec
或其他类型,因此它可以在 PHP 安全模式下运行。
要求
安装了 git 的系统
安装
要使用 composer 安装,您只需运行
composer require lotharthesavior/branch
基本用法
打开仓库
$console = new Console; $repo = Git::open($console, '/path/to/repo'); // GitRepo
创建仓库
$console = new Console; $repo = Git::create($console, '/path/to/repo'); // GitRepo
暂存更改
$repo->add('.');
提交
$repo->commit('Some commit message');
克隆
$localPath = 'local-repo'; $repo = 'repo-url'; $repo->clone( $repo, $localPath );
推送
$repo->push('origin', 'master');
分支
创建
$repo->branchNew( 'name-for-the-branch' );
获取
$repo->branchGet(); // array
获取活动分支
// Git\GitRepo; $repo; $repo->getActiveBranch(); // string
远程
获取
$repo->remote(); // \Git\DTO\Remote[]
添加
$name = 'name'; $address = 'url'; $type = '(fetch)'; $remote = new Remote($name, $address, $type); $repo->remoteAdd($remote);
推送
$branch = new Branch('master'); $remote = new Remote('name', 'url', '(push)'); $repo->push($remote, $branch);
拉取
$branch = new Branch('master'); $remote = new Remote('name', 'url', '(fetch)'); $repo->pull($remote, $branch);
描述
设置
$repo->setDescription( 'Some Description' );
获取
$repo->getDescription(); // string