Copied!

Git repository object.

Main entry point for browsing a Git repository.

CloneableInstantiable
Constants
public Gitonomy\Git\Repository::DEFAULT_DESCRIPTION = 'Unnamed repository; edit this file 'description' to name the repository. '
Methods
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

  • param string $dir path to git repository
  • param array $options array of options values
  • 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.

  • param string $path path to the new repository in which current repository will be cloned
  • param bool $bare flag indicating if repository is bare or has a working-copy
  • return Gitonomy\Git\Repository the newly created 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.

  • param array $revisions An array of revisions to show logs from. Can be
    any text value type
  • param array $paths Restrict log to modifications occurring on given
    paths.
  • param int $offset Start from a given offset in results.
  • param int $limit Limit number of total results.
  • return Gitonomy\Git\Log
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
bare.

  • 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.

  • param string $command Git command to run (checkout, branch, tag)
  • param array $args Arguments of git command
  • 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.

  • param string $command The command to execute
Properties
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
Methods
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:.

  • param string $gitDir directory of a working copy with files checked out
  • param string $workingDir directory containing git files (objects, config...)
© 2022 Bruce Wells
Search Namespaces \ Classes
Configuration