Git repository object.

Main entry point for browsing a Git repository.

Cloneable Instantiable
public Gitonomy\Git\Repository ::DEFAULT_DESCRIPTION = 'Unnamed repository; edit this file 'description' to name the repository. '
public __construct ( $dir , $options = [ ] )

Constructs a new repository.

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

  • throws InvalidArgumentException The folder does not exists
public cloneTo ( $path , $bare = true , array $options = [ ] )

Clones the current repository to a new directory and return instance of new repository.

public getBlame ( $revision , $file , $lineRange = NULL )
public getBlob ( $hash )

Instanciates a blob object or fetches one from the cache.

public getCommit ( $hash )

Instanciates a commit object or fetches one from the cache.

public getDescription ()

Returns description of repository from description file in git directory.

  • return string The description
public getDiff ( $revisions )
  • return Diff
public getGitDir ()

Returns the directory containing git files (git-dir).

  • return string
public getHead ()
public getHeadCommit ()

Returns the HEAD resolved as a commit.

public getHooks ()

Returns the hooks object.

public getLog ( $revisions = NULL , $paths = NULL , $offset = NULL , $limit = NULL )

Returns log for a given set of revisions and paths.

All those values can be null, meaning everything.

public getLogger ()

Returns repository logger.

  • return LoggerInterface the logger or null
public getPath ()

Returns the path to the git repository.

  • return string A directory path
public getReferences ( $reload = false )

Returns the reference list associated to the repository.

public getRevision ( $name )

Instanciates a revision.

public getSize ()

Returns the size of repository, in kilobytes.

  • return int A sum, in kilobytes
public getTree ( $hash )

Instanciates a tree object or fetches one from the cache.

public getWorkingCopy ()
public getWorkingDir ()

Returns the work-tree directory. This may be null if repository is

  • return string path to repository or null if repository is bare
public hasDescription ()

Tests if repository has a custom set description.

  • return bool
public isBare ()

Tests if repository is a bare repository.

  • return bool
public isHeadAttached ()
  • return bool
public isHeadDetached ()
  • return bool
public run ( $command , $args = [ ] )

This command is a facility command. You can run any command
directly on git repository.

  • throws RuntimeException Error while executing git command (debug-mode only)
  • return string Output of a successful process or null if execution failed and debug-mode is disabled.
public setDescription ( $description )

Changes the repository description (file description in git-directory).

public setLogger ( Psr\Log\LoggerInterface $logger )

Set repository logger.

public shell ( $command , array $env = [ ] )

Executes a shell command on the repository, using PHP pipes.

protected $command

Path to git command.

protected $debug

Debug flag, indicating if errors should be thrown.

  • var bool
protected $environmentVariables

Environment variables that should be set for every running process.

  • var array
protected $gitDir

Directory containing git files.

  • var string
protected $inheritEnvironmentVariables
  • var bool
protected $logger

Logger (can be null).

  • var LoggerInterface
protected $objects

Cache containing all objects of the repository.

Associative array, indexed by object hash

  • var array
protected $processTimeout

Timeout that should be set for every running process.

  • var int
protected $referenceBag

Reference bag associated to this repository.

protected $workingDir

Working directory.

  • var string
private getProcess ( $command , $args = [ ] )

This internal method is used to create a process object.

Made private to be sure that process creation is handled through the run method.
run method ensures logging and debug.

  • see \self::run
private initDir ( $gitDir , $workingDir = NULL )

Initializes directory attributes on repository:.

© 2021 Bruce Wells
Search Namespaces \ Classes