PHP Classes

PHP Git Library Provider: Manipulate Git repositories using the git command

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2024-01-10 (10 months ago) RSS 2.0 feedStarStarStarStar 64%Total: 148 All time: 9,109 This week: 40Up
Version License PHP version Categories
git-provider 0.11BSD License5.4PHP 5, Files and Folders, Project Man...
Description 

Author

This class is a wrapper around the git command to manipulate Git repositories.

It can execute the git command to execute several types of operations with Git repositories. Currently it can:

- Create a repository
- Set the repository name and author
- Check if repository files are staged
- Commit changed files
- Remove files from the repository
- Clone repository from given URL
- Check if a repository is empty
- Check if a branch name exists
- Push changes to the origin repository
- Pull changes from an origin repository
- Create branch
- Checkout branch

Picture of Maik Greubel
  Performance   Level  
Name: Maik Greubel <contact>
Classes: 10 packages by
Country: Germany Germany
Age: ???
All time rank: 105967 in Germany Germany
Week rank: 287 Up9 in Germany Germany Up
Innovation award
Innovation award
Nominee: 4x

Example

<?php
use Nkey\GitProvider\GitProvider;

set_include_path(get_include_path() . PATH_SEPARATOR . __DIR__ . "/../src" . PATH_SEPARATOR . __DIR__ . "/../vendor");

require
'autoload.php';

try {
   
// Create a provider instance
   
$bare = new GitProvider("./test.git");

   
// Create a bare repository
   
$bare->create(true, true);

   
// Set the project name
   
$bare->setProjectName("This is only a test repository");

   
// Now we can clone it...

    // First create a provider for the workspace repository
   
$workspace = new GitProvider("./test-workspace");
   
// Clone the bare repository
   
$workspace->cloneFrom($bare->getPath());
   
// First set author to be able to commit
   
$workspace->setAuthor("John Doe", "john@doe.tld");

   
// Add some crucial data to workspace
   
$fd = fopen($workspace->getPath() . "/I-am-some-stupid-file.txt", "w");
    if (
$fd) {
       
fputs($fd, "Hello repository", 16);
       
fflush($fd);
       
fclose($fd);
    }

   
// Add the crucial data to index
   
$workspace->addToIndex("*.txt");

   
// Commit the changes
   
$workspace->commit("Added some super mandatory file with high security content!");

   
// Push everything back to origin
   
$workspace->push();

   
// If you want you can destroy it...
    // $workspace->destroy();
    // $bare->destroy();
    // Or you examine the folders test.git and test-workspace inside example folder
    // using regular git commands to check if everything has worked as expected.
} catch (GitProviderException $ex) {
    echo
$ex->getMessage();
    echo
"\n";
    echo
$ex->getTraceAsString();
}


Details

Build Status Coverage Status

phpGitProvider

This package provides an easy to use git client class for PHP. Here a small example to show the features:

$path = "/path/to/where/you/want/to/work/on/your/repo";

$provider = new GitProvider($path);

// Create a shared bare repository
$provider->create(true, true);
// Set the author of the repo
$provider->setAuthor("John Doe", "john@doe.tld");
// Provide a project name
$provider->setProjectName('A test repository');

// Some data to repository (file must exist)
$provider->addToIndex("README.md");

// Commit your changes with a speaking message
$provider->commit("Added README");

  Files folder image Files (18)  
File Role Description
Files folder imagecontrib (2 files)
Files folder imageexample (2 files)
Files folder imagesrc (2 files)
Files folder imagetests (1 directory)
Accessible without login Plain text file .gitignore Data git ignore configuration
Accessible without login Plain text file .travis.yml Data Travis Ci configuration
Accessible without login Plain text file build.xml Data Ant build script
Accessible without login Plain text file composer.json Data Composer control file
Accessible without login Plain text file LICENSE Lic. License
Accessible without login Plain text file phpcs.xml Data PHP Codesniffer configuration
Accessible without login Plain text file phpdox.xml Data phpdox configuration
Accessible without login Plain text file phpmd.xml Data PHP Messdetection configuration
Accessible without login Plain text file phpunit.xml Data PHPUnit configuration
Accessible without login Plain text file README.md Data Readme

  Files folder image Files (18)  /  contrib  
File Role Description
  Accessible without login Plain text file phpcs.xsd Data Contributed schema for code sniffer configuration
  Accessible without login Plain text file phpunit.xsd Data Contributed schema for phpunit configuration

  Files folder image Files (18)  /  example  
File Role Description
  Accessible without login Plain text file .gitignore Data git ignore
  Accessible without login Plain text file basic-example.php Example Basic example

  Files folder image Files (18)  /  src  
File Role Description
  Accessible without login Plain text file GitProvider.php Class The main class
  Accessible without login Plain text file GitProviderException.php Class Derived exception

  Files folder image Files (18)  /  tests  
File Role Description
Files folder imageprovider-tests (2 files)

  Files folder image Files (18)  /  tests  /  provider-tests  
File Role Description
  Accessible without login Plain text file FailureTest.php Test Unit test
  Accessible without login Plain text file GitProviderTest.php Test Unit test

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
Downloadgit-provider-2024-01-10.zip 15KB
Downloadgit-provider-2024-01-10.tar.gz 11KB
Install with ComposerInstall with Composer
Needed packages  
Class DownloadWhy it is needed Dependency
PHP Generics Download .zip .tar.gz Several general purpose classes such as Directory and logging exists already there Required
 Version Control Unique User Downloads Download Rankings  
 100%
Total:148
This week:0
All time:9,109
This week:40Up
 User Ratings  
 
 All time
Utility:83%StarStarStarStarStar
Consistency:83%StarStarStarStarStar
Documentation:-
Examples:66%StarStarStarStar
Tests:75%StarStarStarStar
Videos:-
Overall:64%StarStarStarStar
Rank:740