<?php
namespace Git;
class Client
{
protected $path;
public function __construct($path)
{
$this->setPath($path);
}
/**
* Creates a new repository on the specified path
* @param string $path Path where the new repository will be created
* @return Repository Instance of Repository
*/
public function createRepository($path)
{
if (file_exists($path . '/.git/HEAD') && !file_exists($path . '/HEAD')) {
throw new \RuntimeException('A GIT repository already exists at ' . $path);
}
$repository = new Repository($path, $this);
return $repository->create();
}
/**
* Opens a repository at the specified path
* @param string $path Path where the repository is located
* @return Repository Instance of Repository
*/
public function getRepository($path)
{
if (!file_exists($path) || !file_exists($path . '/.git/HEAD') && !file_exists($path . '/HEAD')) {
throw new \RuntimeException('There is no GIT repository at ' . $path);
}
return new Repository($path, $this);
}
/**
* Searches for valid repositories on the specified path
* @param string $path Path where repositories will be searched
* @return array Found repositories, containing their name, path and description
*/
public function getRepositories($path)
$description = $file->getPathname() . '/.git/description';
}
if (file_exists($description)) {
$description = file_get_contents($description);
} else {
$description = 'There is no repository description file. Please, create one to remove this message.';
* @param Repository $repository Repository where the command will be run
* @param string $command Git command to be run
* @return string Returns the command output
*/
public function run(Repository $repository, $command)
{