PHP Class Gitonomy\Git\Repository

Main entry point for browsing a Git repository.
Author: Alexandre Salomé ([email protected])
Datei anzeigen Open project: gitonomy/gitlib Class Usage Examples

Protected Properties

Property Type Description
$command Path to git command.
$debug boolean Debug flag, indicating if errors should be thrown.
$environmentVariables array Environment variables that should be set for every running process.
$gitDir string Directory containing git files.
$logger Psr\Log\LoggerInterface Logger (can be null).
$objects array Associative array, indexed by object hash
$processTimeout integer Timeout that should be set for every running process.
$referenceBag Gitonomy\Git\ReferenceBag Reference bag associated to this repository.
$workingDir string Working directory.

Public Methods

Method Description
__construct ( string $dir, array $options = [] ) Constructs a new repository.
cloneTo ( string $path, boolean $bare = true, array $options = [] ) : Repository Clones the current repository to a new directory and return instance of new repository.
getBlame ( $revision, $file, $lineRange = null )
getBlob ( string $hash ) : Gitonomy\Git\Blob Instanciates a blob object or fetches one from the cache.
getCommit ( string $hash ) : Gitonomy\Git\Commit Instanciates a commit object or fetches one from the cache.
getDescription ( ) : string Returns description of repository from description file in git directory.
getDiff ( $revisions ) : Gitonomy\Git\Diff\Diff
getGitDir ( ) : string Returns the directory containing git files (git-dir).
getHead ( ) : Gitonomy\Git\Reference | Gitonomy\Git\Commit | null
getHeadCommit ( ) : Gitonomy\Git\Commit | null Returns the HEAD resolved as a commit.
getHooks ( ) : Gitonomy\Git\Hooks Returns the hooks object.
getLog ( array $revisions = null, array $paths = null, integer $offset = null, integer $limit = null ) : Gitonomy\Git\Log Returns log for a given set of revisions and paths.
getLogger ( ) : Psr\Log\LoggerInterface Returns repository logger.
getPath ( ) : string Returns the path to the git repository.
getReferences ( ) : Gitonomy\Git\ReferenceBag Returns the reference list associated to the repository.
getRevision ( string $name ) : Gitonomy\Git\Revision Instanciates a revision.
getSize ( ) : integer Returns the size of repository, in kilobytes.
getTree ( string $hash ) : Gitonomy\Git\Tree Instanciates a tree object or fetches one from the cache.
getWorkingCopy ( ) : Gitonomy\Git\WorkingCopy
getWorkingDir ( ) : string Returns the work-tree directory. This may be null if repository is bare.
hasDescription ( ) : boolean Tests if repository has a custom set description.
isBare ( ) : boolean Tests if repository is a bare repository.
isHeadAttached ( ) : boolean
isHeadDetached ( ) : boolean
run ( string $command, array $args = [] ) : string This command is a facility command. You can run any command directly on git repository.
setDescription ( $description ) : Repository Changes the repository description (file description in git-directory).
setLogger ( Psr\Log\LoggerInterface $logger ) : Repository Set repository logger.
shell ( string $command, array $env = [] ) Executes a shell command on the repository, using PHP pipes.

Private Methods

Method Description
getProcess ( $command, $args = [] ) This internal method is used to create a process object.
initDir ( string $gitDir, string $workingDir = null ) Initializes directory attributes on repository:.

Method Details

__construct() public method

Available options are: * working_dir : specify where working copy is located (option --work-tree) * debug : (default: true) enable/disable minimize errors and reduce log level * logger : a logger to use for logging actions (Psr\Log\LoggerInterface) * environment_variables : define environment variables for every ran process
public __construct ( string $dir, array $options = [] )
$dir string path to git repository
$options array array of options values

cloneTo() public method

Clones the current repository to a new directory and return instance of new repository.
public cloneTo ( string $path, boolean $bare = true, array $options = [] ) : Repository
$path string path to the new repository in which current repository will be cloned
$bare boolean flag indicating if repository is bare or has a working-copy
$options array
return Repository the newly created repository

getBlame() public method

public getBlame ( $revision, $file, $lineRange = null )

getBlob() public method

Instanciates a blob object or fetches one from the cache.
public getBlob ( string $hash ) : Gitonomy\Git\Blob
$hash string A blob hash, with a length of 40
return Gitonomy\Git\Blob

getCommit() public method

Instanciates a commit object or fetches one from the cache.
public getCommit ( string $hash ) : Gitonomy\Git\Commit
$hash string A commit hash, with a length of 40
return Gitonomy\Git\Commit

getDescription() public method

Returns description of repository from description file in git directory.
public getDescription ( ) : string
return string The description

getDiff() public method

public getDiff ( $revisions ) : Gitonomy\Git\Diff\Diff
return Gitonomy\Git\Diff\Diff

getGitDir() public method

Returns the directory containing git files (git-dir).
public getGitDir ( ) : string
return string

getHead() public method

public getHead ( ) : Gitonomy\Git\Reference | Gitonomy\Git\Commit | null
return Gitonomy\Git\Reference | Gitonomy\Git\Commit | null current HEAD object or null if error occurs

getHeadCommit() public method

Returns the HEAD resolved as a commit.
public getHeadCommit ( ) : Gitonomy\Git\Commit | null
return Gitonomy\Git\Commit | null returns a Commit or ``null`` if repository is empty

getHooks() public method

Returns the hooks object.
public getHooks ( ) : Gitonomy\Git\Hooks
return Gitonomy\Git\Hooks

getLog() public method

All those values can be null, meaning everything.
public getLog ( array $revisions = null, array $paths = null, integer $offset = null, integer $limit = null ) : Gitonomy\Git\Log
$revisions array An array of revisions to show logs from. Can be any text value type
$paths array Restrict log to modifications occurring on given paths.
$offset integer Start from a given offset in results.
$limit integer Limit number of total results.
return Gitonomy\Git\Log

getLogger() public method

Returns repository logger.
public getLogger ( ) : Psr\Log\LoggerInterface
return Psr\Log\LoggerInterface the logger or null

getPath() public method

Returns the path to the git repository.
public getPath ( ) : string
return string A directory path

getReferences() public method

Returns the reference list associated to the repository.
public getReferences ( ) : Gitonomy\Git\ReferenceBag
return Gitonomy\Git\ReferenceBag

getRevision() public method

Instanciates a revision.
public getRevision ( string $name ) : Gitonomy\Git\Revision
$name string Name of the revision
return Gitonomy\Git\Revision

getSize() public method

Returns the size of repository, in kilobytes.
public getSize ( ) : integer
return integer A sum, in kilobytes

getTree() public method

Instanciates a tree object or fetches one from the cache.
public getTree ( string $hash ) : Gitonomy\Git\Tree
$hash string A tree hash, with a length of 40
return Gitonomy\Git\Tree

getWorkingCopy() public method

public getWorkingCopy ( ) : Gitonomy\Git\WorkingCopy
return Gitonomy\Git\WorkingCopy

getWorkingDir() public method

Returns the work-tree directory. This may be null if repository is bare.
public getWorkingDir ( ) : string
return string path to repository or null if repository is bare

hasDescription() public method

Tests if repository has a custom set description.
public hasDescription ( ) : boolean
return boolean

isBare() public method

Tests if repository is a bare repository.
public isBare ( ) : boolean
return boolean

isHeadAttached() public method

public isHeadAttached ( ) : boolean
return boolean

isHeadDetached() public method

public isHeadDetached ( ) : boolean
return boolean

run() public method

This command is a facility command. You can run any command directly on git repository.
public run ( string $command, array $args = [] ) : string
$command string Git command to run (checkout, branch, tag)
$args array Arguments of git command
return string Output of a successful process or null if execution failed and debug-mode is disabled.

setDescription() public method

Changes the repository description (file description in git-directory).
public setDescription ( $description ) : Repository
return Repository the current repository

setLogger() public method

Set repository logger.
public setLogger ( Psr\Log\LoggerInterface $logger ) : Repository
$logger Psr\Log\LoggerInterface A logger
return Repository The current repository

shell() public method

Executes a shell command on the repository, using PHP pipes.
public shell ( string $command, array $env = [] )
$command string The command to execute
$env array

Property Details

$command protected_oe property

Path to git command.
protected $command

$debug protected_oe property

Debug flag, indicating if errors should be thrown.
protected bool $debug
return boolean

$environmentVariables protected_oe property

Environment variables that should be set for every running process.
protected array $environmentVariables
return array

$gitDir protected_oe property

Directory containing git files.
protected string $gitDir
return string

$logger protected_oe property

Logger (can be null).
protected LoggerInterface,Psr\Log $logger
return Psr\Log\LoggerInterface

$objects protected_oe property

Associative array, indexed by object hash
protected array $objects
return array

$processTimeout protected_oe property

Timeout that should be set for every running process.
protected int $processTimeout
return integer

$referenceBag protected_oe property

Reference bag associated to this repository.
protected ReferenceBag,Gitonomy\Git $referenceBag
return Gitonomy\Git\ReferenceBag

$workingDir protected_oe property

Working directory.
protected string $workingDir
return string