ride/lib-vcs

Ride框架的版本控制抽象库

1.0.0 2016-10-07 11:01 UTC

This package is auto-updated.

Last update: 2024-09-13 00:12:15 UTC


README

PHP Ride框架的简单版本控制抽象库。

库中包含的内容

仓库

Repository 接口代表任何版本控制系统中的仓库。您可以使用它来获取关于仓库的信息或操作仓库。

目前仅通过 GitRepository 类实现了 git。

提交日志

CommitLog 类用作单个提交的数据容器。

代码示例

查看此代码示例以了解该库的功能

<?php

use ride\library\system\System;
use ride\library\vcs\git\GenericGitLogParser;
use ride\library\vcs\git\GitClient;
use ride\library\vcs\git\GitRepository;
use ride\library\vcs\Respository;

function createGitRepository(System $system) {
    $gitClient = new GitClient($system);
    $gitLogParser = new GenericGitLogParser();

    $gitRepository = new GitRepository($gitClient, $gitLogParser);
    $gitRepository->setUrl('git@github.com:all-ride/ride-lib-vcs.git');
    $gitRepository->setWorkingCopy($system->getFileSystem()->getFile('/path/to/local/copy'));
    
    // optionally, set a private key
    $gitRepository->setPrivateKey('/path/to/private.key');
    
    return $gitRepository;
}

function useRepository(Repository $repository) {
    if (!$repository->isCreated()) {
        // create the working copy the first time
        $repository->create();
        
        // perform the initial checkout to retrieve everything in the local copy
        $repository->checkout();
    }
    
    // perform an update or pull
    $repository->update();
    
    // deal with branches
    $currentBranch = $repository->getBranch();
    $availableBranches = $repository->getBranches();
    
    if (!$repository->hasBranch('my-branch')) {
        $repository->createBranch('my-branch');
    }
    
    // retrieve information about commits
    $currentRevision = $repository->getRevision();
    
    $commit = $repository->getCommit($currentRevision);
    if ($commit) {
        echo $commit->message;
        echo $commit->author;
    }
    
    $commits = $repository->getCommits();
    $commits = $repository->getCommits('src/ride/library/vcs/Repository.php');
    
    $sinceCommit = 'a1b2c3';
    $untilCommit = 'z9y8x7';
    $commits = $repository->getCommits('src/ride/library/vcs/Repository.php', 5, $sinceCommit, $untilCommit);
    
    // perform commits
    $repository->add('src/ride/library/vcs/git'); // a folder
    $repository->add('src/ride/library/vcs/git/git-ssh.sh'); // a directory
    
    $repository->remove('.gitignore');
    
    $repository->commit('added git implementation');
}

实现

更多示例,您可以查看以下库的实现

安装

您可以使用 Composer 安装此库。

composer require ride/lib-vcs