PHP code example of ride / lib-vcs

1. Go to this page and download the library: Download ride/lib-vcs library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ride / lib-vcs example snippets




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('[email protected]: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');
}