contao-community-alliance/build-system-repository-git

此包已被放弃,不再维护。作者建议使用bit3/git-php包。

CCABS的GIT仓库。

dev-master / 1.0.x-dev 2014-09-19 12:53 UTC

This package is not auto-updated.

Last update: 2019-02-20 17:52:37 UTC


README

Build Status

这是一个轻量级的git适配器,提供PHP中的git命令。

使用示例

API使用命令构建器,允许您构建一个命令并一次性执行它。

主要概要是

$git->command()->option()->execute();

$git->command()将创建一个新的命令,*->option()将向命令中添加一个选项,而*->execute()将最终执行该命令。

命令和选项的命名遵循git命名。如果您想查找特定命令或选项的文档,只需查看git文档。您将在那里找到命令/选项。

初始化一个新的git仓库

use ContaoCommunityAlliance\BuildSystem\Repository\GitRepository;

$directory = '/path/to/git/target/directory';

$git = new GitRepository($directory);
$git->init()->execute();

克隆一个git仓库

因为clone是PHP中的保留词,所以clone命令被命名为cloneRepository()

use ContaoCommunityAlliance\BuildSystem\Repository\GitRepository;

$directory = '/path/to/git/target/directory';

$git = new GitRepository($directory);
$git->cloneRepository()->execute();

describe

$annotatedTag   = $git->describe()->execute();
$lightweightTag = $git->describe()->tags()->execute();
$recentRef      = $git->describe()->all()->execute();

设置远程fetch URL

$git->remote()
	->setUrl('origin', 'git@github.com:contao-community-alliance/build-system-repository-git.git')
	->execute();

设置远程push URL

$git->remote()
	->setPushUrl('origin', 'git@github.com:contao-community-alliance/build-system-repository-git.git')
	->execute();

添加新的远程仓库

$git->remote()
	->add('github', 'git@github.com:contao-community-alliance/build-system-repository-git.git')
	->execute();

获取远程对象

$git->fetch()->execute('github');

checkout

$git->checkout()->execute('hotfix/1.2.3');

检出特定路径

$git->checkout()->execute('hotfix/1.2.3', '/fileA', '/fileB', '/dir/fileC');

推送对象

$git->push()->execute('github', 'hotfix/1.2.3');

将文件添加到暂存索引

$git->add()->execute('file/to/add.ext');

移除文件

$git->rm()->execute('file/to/remove.ext');

提交更改

$git->commit()->message('Commit message')->execute();

创建标签

$git->tag()->execute('v1.2.3');

便捷和快捷方法

列出远程仓库

$remotes = $git->remote()->getNames();

// array(
//     'origin',
//     'composer',
// )

列出分支

$remotes = $git->branch()->getNames();

// array(
//     'master',
//     'hotfix/1.2.3',
// )

列出远程跟踪分支

$remotes = $git->branch()->remotes()->->getNames();

// array(
//     'origin/master',
//     'origin/hotfix/1.2.3',
//     'origin/release/4.5.6',
// )

列出包括远程跟踪分支的分支

$remotes = $git->branch()->all()->->getNames();

// array(
//     'master',
//     'hotfix/1.2.3',
//     'remotes/origin/master',
//     'remotes/origin/hotfix/1.2.3',
//     'remotes/origin/release/4.5.6',
// )

获取修改状态

$status = $git->status()->getStatus();

// array(
//     'existing-file.txt'      => array('index' => 'D',   'worktree' => false),
//     'removed-but-staged.txt' => array('index' => 'D',   'worktree' => 'A'),
//     'staged-file.txt'        => array('index' => false, 'worktree' => 'A'),
//     'unknown-file.txt'       => array('index' => '?',   'worktree' => '?'),
// )

获取索引修改状态

$status = $git->status()->getIndexStatus();

// array(
//     'existing-file.txt'      => 'D',
//     'removed-but-staged.txt' => 'D',
//     'staged-file.txt'        => false,
//     'unknown-file.txt'       => '?',
// )

获取工作树修改状态

$status = $git->status()->getWorkTreeStatus();

// array(
//     'existing-file.txt'      => 'worktree' => false,
//     'removed-but-staged.txt' => 'worktree' => 'A',
//     'staged-file.txt'        => 'worktree' => 'A',
//     'unknown-file.txt'       => 'worktree' => '?',
// )