Git repository object.

Main entry point for browsing a Git repository.

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

  • 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 \Repository the newly created repository
public getBlame( $revision, $file, $lineRange = NULL)
  • return \Blame
public getBlob( $hash)

Instanciates a blob object or fetches one from the cache.

  • param string $hash A blob hash, with a length of 40
  • return \Blob
public getCommit( $hash)

Instanciates a commit object or fetches one from the cache.

  • param string $hash A commit hash, with a length of 40
  • return \Commit
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()
  • throws \RuntimeException Unable to find file HEAD (debug-mode only)
  • return \Reference|\Commit|null current HEAD object or null if error occurs
public getHeadCommit()

Returns the HEAD resolved as a commit.

  • return \Commit|null returns a Commit or null if repository is empty
public getHooks()

Returns the hooks object.

  • return \Hooks
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 \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.

  • param bool $reload Reload references from the filesystem
  • return \ReferenceBag
public getRevision( $name)

Instanciates a revision.

  • param string $name Name of the revision
  • return \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.

  • param string $hash A tree hash, with a length of 40
  • return \Tree
public getWorkingCopy()
  • return \WorkingCopy
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).

  • return \Repository the current repository
public setLogger(Psr\Log\LoggerInterface $logger)

Set repository logger.

  • param \LoggerInterface $logger A logger
  • return \Repository The current repository
public shell( $command, array $env = [])

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

  • param string $command The command to execute
protected $command = NULL

Path to git command.

protected $debug = NULL

Debug flag, indicating if errors should be thrown.

  • var bool
protected $environmentVariables = NULL

Environment variables that should be set for every running process.

  • var array
protected $gitDir = NULL

Directory containing git files.

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

Logger (can be null).

  • var \LoggerInterface
protected $objects = NULL

Cache containing all objects of the repository.

Associative array, indexed by object hash

  • var array
protected $processTimeout = NULL

Timeout that should be set for every running process.

  • var int
protected $referenceBag = NULL

Reference bag associated to this repository.

  • var \ReferenceBag
protected $workingDir = NULL

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

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