PHP Classes

File: example/basic-example.php

Recommend this page to a friend!
  Classes of Maik Greubel   PHP Git Library Provider   example/basic-example.php   Download  
File: example/basic-example.php
Role: Example script
Content type: text/plain
Description: Basic example
Class: PHP Git Library Provider
Manipulate Git repositories using the git command
Author: By
Last change: Update of example/basic-example.php
Date: 5 months ago
Size: 1,603 bytes


Class file image Download
use Nkey\GitProvider\GitProvider;

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


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
// 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);

// Add the crucial data to index

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

// Push everything back to origin

// 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) {