### Install Gitlib via Composer Source: https://github.com/gitonomy/gitlib/blob/main/README.md Methods to add the library to your project using the command line or by modifying the composer.json file. ```bash $ composer require gitonomy/gitlib ``` ```json { "require": { "gitonomy/gitlib": "^1.3" } } ``` -------------------------------- ### Recursively Display Commit History Source: https://github.com/gitonomy/gitlib/blob/main/doc/commit.md Example function to traverse and display a commit and all its ancestors. ```php function displayLog(Gitonomy\Git\Commit $commit) { echo '- '.$commit->getShortMessage().PHP_EOL; foreach ($commit->getParents() as $parent) { displayLog($parent); } } ``` -------------------------------- ### Retrieve Repository Size Source: https://github.com/gitonomy/gitlib/blob/main/doc/repository.md Get the repository size in kilobytes. Note that this method is only tested on Linux systems. ```php $size = $repository->getSize(); echo 'Your repository size is '.$size.'KB'; ``` -------------------------------- ### Blame::getLines Source: https://github.com/gitonomy/gitlib/blob/main/doc/blame.md Retrieves all lines of the file as an array indexed starting from 1. ```APIDOC ## Blame::getLines ### Description Returns an array of Line objects indexed by line number. ### Signature `$blame->getLines()` ### Returns - **array** - An array of Line objects. ``` -------------------------------- ### Get Blob Content Source: https://github.com/gitonomy/gitlib/blob/main/doc/blob.md Retrieve the raw content stored within a blob object. ```php echo $blob->getContent(); ``` -------------------------------- ### Retrieving Pending Modifications Source: https://github.com/gitonomy/gitlib/blob/main/doc/workingcopy.md Get a Diff object representing pending changes on tracked files. ```php $diff = $wc->getDiffPending(); ``` -------------------------------- ### Retrieving Staged Modifications Source: https://github.com/gitonomy/gitlib/blob/main/doc/workingcopy.md Get a Diff object representing changes currently in the staging area. ```php $diff = $wc->getDiffStaged(); ``` -------------------------------- ### Get Last File Modification Source: https://github.com/gitonomy/gitlib/blob/main/doc/commit.md Retrieve the last commit that modified a specific file. ```php $last = $commit->getLastModification('README'); echo 'Last README modification'.PHP_EOL; echo ' Author: '.$last->getAuthorName().PHP_EOL; echo ' Date: '.$last->getAuthorDate()->format('d/m/Y').PHP_EOL; echo ' Message: '.$last->getMessage(); ``` -------------------------------- ### Initialize a Repository Source: https://github.com/gitonomy/gitlib/blob/main/doc/repository.md Create a new Repository instance by providing the filesystem path to the repository. ```php $repository = new Repository('/path/to/repo'); ``` -------------------------------- ### Initialize a Git repository Source: https://github.com/gitonomy/gitlib/blob/main/doc/admin.md Use Admin::init to create a new repository. The default behavior creates a bare repository unless false is passed as the second argument. ```php // Initialize a bare repository $repository = Gitonomy\Git\Admin::init('/path/to/repository'); // Initialize a non-bare repository $repository = Gitonomy\Git\Admin::init('/path/to/repository', false); ``` -------------------------------- ### Admin::init Source: https://github.com/gitonomy/gitlib/blob/main/doc/admin.md Initializes a new git repository at the specified path. ```APIDOC ## Admin::init ### Description Initializes a new git repository. By default, it creates a bare repository. ### Signature `Gitonomy\Git\Admin::init(string $path, bool $bare = true)` ### Parameters - **$path** (string) - Required - The filesystem path where the repository will be initialized. - **$bare** (bool) - Optional - Whether to create a bare repository. Defaults to true. ``` -------------------------------- ### Access Repository and List Branches Source: https://github.com/gitonomy/gitlib/blob/main/README.md Initialize a repository object and iterate through its branches, followed by executing a raw git command. ```php getReferences()->getBranches() as $branch) { echo '- '.$branch->getName().PHP_EOL; } $repository->run('fetch', ['--all']); ``` -------------------------------- ### Configure Repository Options Source: https://github.com/gitonomy/gitlib/blob/main/doc/repository.md Pass an array of options to the constructor to customize behavior like logging and debug settings. ```php $repository = new Repository('/path/to/repo', [ 'debug' => true, 'logger' => new Monolog ullLogger(), ]); ``` -------------------------------- ### Configure Repository Logger Source: https://github.com/gitonomy/gitlib/blob/main/doc/repository.md Set up logging to track executed commands, either via setter or constructor options. ```php $repository->setLogger(new Monolog ullLogger('repository')); $repository->run('fetch', ['--all']); ``` ```php $logger = new MonologLogger('repository'); $repository = new Repository('/path/foo', ['logger' => $logger]); $repository->run('fetch', ['--all']); ``` -------------------------------- ### Creating a hook via file content Source: https://github.com/gitonomy/gitlib/blob/main/doc/hooks.md Create a new hook file with specific content and set it as executable. ```php $content = <<set('pre-receive', $content); ``` -------------------------------- ### Creating a hook via symlink Source: https://github.com/gitonomy/gitlib/blob/main/doc/hooks.md Create a hook by linking to an existing file. Throws LogicException if the hook exists. ```php $hooks->setSymlink('pre-receive', '/path/to/file-to-link'); ``` -------------------------------- ### Retrieve Log Object Source: https://github.com/gitonomy/gitlib/blob/main/doc/log.md Initializes a log object from a repository instance. ```php $log = $repository->getLog(); ``` -------------------------------- ### Specify Git Binary Path Source: https://github.com/gitonomy/gitlib/blob/main/doc/repository.md Use the command option to define the path to the git binary. ```php $repository = new Gitonomy\Git\Repository('/tmp/foo', ['command' => '/home/alice/bin/git']); ``` -------------------------------- ### Retrieve a Commit from a Repository Source: https://github.com/gitonomy/gitlib/blob/main/doc/commit.md Initialize a repository object and fetch a specific commit using its hash. ```php $repository = new Gitonomy\Git\Repository('/path/to/repository'); $commit = $repository->getCommit('a7c8d2b4'); ``` -------------------------------- ### Mirror a repository Source: https://github.com/gitonomy/gitlib/blob/main/doc/admin.md Use mirrorTo to fully mirror a repository and all its references. ```php // Mirror to a bare repository $mirror = Gitonomy\Git\Admin::mirrorTo('/tmp/mirror', 'https://github.com/gitonomy/gitlib.git'); // Mirror to a non-bare repository $mirror = Gitonomy\Git\Admin::mirrorTo('/tmp/mirror', 'https://github.com/gitonomy/gitlib.git', false); ``` -------------------------------- ### Clone a repository from a URL Source: https://github.com/gitonomy/gitlib/blob/main/doc/admin.md Clone a remote repository to a local path. Defaults to a bare repository unless specified otherwise. ```php // Clone to a bare repository $repository = Gitonomy\Git\Admin::cloneTo('/tmp/gitlib', 'https://github.com/gitonomy/gitlib.git'); // Clone to a non-bare repository $repository = Gitonomy\Git\Admin::cloneTo('/tmp/gitlib', 'https://github.com/gitonomy/gitlib.git', false); ``` -------------------------------- ### Clone an existing Repository instance Source: https://github.com/gitonomy/gitlib/blob/main/doc/admin.md Use the cloneTo method on an existing Repository object to create a copy. ```php $new = $repository->cloneTo('/tmp/clone'); ``` -------------------------------- ### Hooks::set Source: https://github.com/gitonomy/gitlib/blob/main/doc/hooks.md Creates or overwrites a hook file with specific content. ```APIDOC ## Hooks::set(string $name, string $content) ### Description Creates a new file in the hooks directory, writes the provided content, and makes it executable. ### Parameters - **name** (string) - Required - The name of the hook. - **content** (string) - Required - The script content to write to the hook file. ### Exceptions - **LogicException** - Thrown if the hook already exists. ``` -------------------------------- ### Accessing the Working Copy Source: https://github.com/gitonomy/gitlib/blob/main/doc/workingcopy.md Retrieve the working copy object from a repository instance. ```php $repo = new Repository('/path/to/working-dir'); $wc = $repo->getWorkingCopy(); ``` -------------------------------- ### Check if Repository is Bare Source: https://github.com/gitonomy/gitlib/blob/main/doc/repository.md Determine if the repository is bare using the isBare method. ```php $repository->isBare(); ``` -------------------------------- ### Log Pagination Methods Source: https://github.com/gitonomy/gitlib/blob/main/doc/log.md Methods to configure or retrieve the offset and limit for the log query. ```APIDOC ## Log Pagination ### Methods - `setOffset(int $offset)` - Sets the number of commits to skip. - `setLimit(int $limit)` - Sets the maximum number of commits to return. - `getOffset()` - Returns the current offset. - `getLimit()` - Returns the current limit. ``` -------------------------------- ### Check Existence of References Source: https://github.com/gitonomy/gitlib/blob/main/doc/references.md Verify if specific branches or tags exist within the repository. ```php if ($references->hasBranch('master') && $references->hasTag('0.1')) { echo 'Good start!'.PHP_EOL; } ``` -------------------------------- ### Admin::mirrorTo Source: https://github.com/gitonomy/gitlib/blob/main/doc/admin.md Mirrors a repository and all its references. ```APIDOC ## Admin::mirrorTo ### Description Fully mirrors a repository including all references. ### Signature `Gitonomy\Git\Admin::mirrorTo(string $path, string $url, bool $bare = true)` ### Parameters - **$path** (string) - Required - The local destination path. - **$url** (string) - Required - The remote repository URL. - **$bare** (bool) - Optional - Whether to create a bare repository. Defaults to true. ``` -------------------------------- ### Inspect Line object properties in PHP Source: https://github.com/gitonomy/gitlib/blob/main/doc/blame.md Demonstrates how to extract commit information and content from a Line object. ```php $line->getCommit(); // returns a Commit $line->getContent(); // returns text // you can access author from commmit: $author = $line->getCommit()->getAuthorName(); ``` -------------------------------- ### Manage Pagination Source: https://github.com/gitonomy/gitlib/blob/main/doc/log.md Sets and retrieves offset and limit values for log pagination. ```php $log->setOffset(32); $log->setLimit(40); // or read it: $log->getOffset(); $log->getLimit(); ``` -------------------------------- ### Filter Log History Source: https://github.com/gitonomy/gitlib/blob/main/doc/log.md Demonstrates various ways to filter logs by branch, file path, offset, and limit. ```php // Global log for repository $log = $repository->getLog(); // Log for master branch $log = $repository->getLog('master'); // Returns last 10 commits on README file $log = $repository->getLog('master', 'README', 0, 10); // Returns last 10 commits on README or UPGRADE files $log = $repository->getLog('master', ['README', 'UPGRADE'], 0, 10); ``` -------------------------------- ### Create and Delete References Source: https://github.com/gitonomy/gitlib/blob/main/doc/references.md Create new branches or tags from a commit hash, or delete existing references. ```php // create a branch $references = $repository->getReferences(); $branch = $references->createBranch('foobar', 'a8b7e4...'); // commit to reference // create a tag $references = $repository->getReferences(); $tag = $references->createTag('0.3', 'a8b7e4...'); // commit to reference // delete a branch or a tag $branch->delete(); ``` -------------------------------- ### Access Specific Branch or Tag Source: https://github.com/gitonomy/gitlib/blob/main/doc/references.md Retrieve individual Branch or Tag objects by name. Throws ReferenceNotFoundException if the reference is missing. ```php $master = $references->getBranch('master'); $feat123 = $references->getLocalBranch('feat123'); $feat456 = $references->getRemoteBranch('origin/feat456'); $v0_1 = $references->getTag('0.1'); ``` -------------------------------- ### Retrieve ReferenceBag from Repository Source: https://github.com/gitonomy/gitlib/blob/main/doc/references.md Obtain the ReferenceBag object from a repository instance to begin interacting with tags and branches. ```php $references = $repository->getReferences(); ``` -------------------------------- ### File Class Methods Source: https://github.com/gitonomy/gitlib/blob/main/doc/diff.md Exhaustive list of methods available on a File object for checking modification types and line counts. ```php $file->getOldName(); $file->getNewName(); $file->getOldDiff(); $file->getNewDiff(); $file->isCreation(); $file->isDeletion(); $file->isModification(); $file->isRename(); $file->isChangeMode(); $file->getAdditions(); // Number of added lines $file->getDeletions(); // Number of deleted lines $file->isBinary(); // Binary files have no "lines" $file->getChanges(); // See next chapter ``` -------------------------------- ### Checking out a Revision Source: https://github.com/gitonomy/gitlib/blob/main/doc/workingcopy.md Perform a checkout operation on the working copy, optionally creating a new branch. ```php // git checkout master $wc->checkout('master'); // git checkout origin/master -b master $wc->checkout('origin/master', 'master'); ``` -------------------------------- ### ReferenceBag Methods Source: https://github.com/gitonomy/gitlib/blob/main/doc/references.md Methods for accessing, creating, and resolving branches and tags within a repository. ```APIDOC ## ReferenceBag API ### Description The ReferenceBag object provides methods to interact with repository references. It is retrieved via `$repository->getReferences()`. ### Methods - **hasBranch(string $name)**: Checks if a branch exists. - **hasTag(string $name)**: Checks if a tag exists. - **getBranches()**: Returns all branches. - **getLocalBranches()**: Returns all local branches. - **getRemoteBranches()**: Returns all remote branches. - **getTags()**: Returns all tags. - **getAll()**: Returns all references. - **getBranch(string $name)**: Returns a Branch object. - **getLocalBranch(string $name)**: Returns a local Branch object. - **getRemoteBranch(string $name)**: Returns a remote Branch object. - **getTag(string $name)**: Returns a Tag object. - **createBranch(string $name, string $commit)**: Creates a new branch at the specified commit. - **createTag(string $name, string $commit)**: Creates a new tag at the specified commit. - **resolveBranches(mixed $commit)**: Resolves branches from a commit object or hash. - **resolveTags(mixed $commit)**: Resolves tags from a commit object or hash. - **resolve(mixed $commit)**: Resolves all branches and tags from a commit object or hash. ``` -------------------------------- ### Set Environment Variables Source: https://github.com/gitonomy/gitlib/blob/main/doc/repository.md Pass environment variables to the underlying git sub-process. ```php $repository = new Gitonomy\Git\Repository('/tmp/foo', ['environment_variables' => ['GIT_']]) ``` -------------------------------- ### Gitonomy\Git\Blob::getContent Source: https://github.com/gitonomy/gitlib/blob/main/doc/blob.md Retrieves the raw content of the blob. ```APIDOC ## Method: getContent ### Description Returns the content of the blob object. ### Signature `string getContent()` ### Example ```php echo $blob->getContent(); ``` ``` -------------------------------- ### Accessing the Hooks object Source: https://github.com/gitonomy/gitlib/blob/main/doc/hooks.md Retrieve the Hooks object from a Repository instance. ```php $hooks = $repository->getHooks(); ``` -------------------------------- ### Admin::cloneTo Source: https://github.com/gitonomy/gitlib/blob/main/doc/admin.md Clones a repository from a remote URL to a local path. ```APIDOC ## Admin::cloneTo ### Description Clones a remote repository to a local directory. Defaults to creating a bare repository. ### Signature `Gitonomy\Git\Admin::cloneTo(string $path, string $url, bool $bare = true)` ### Parameters - **$path** (string) - Required - The local destination path. - **$url** (string) - Required - The remote repository URL. - **$bare** (bool) - Optional - Whether to create a bare repository. Defaults to true. ``` -------------------------------- ### Hooks::get Source: https://github.com/gitonomy/gitlib/blob/main/doc/hooks.md Retrieves the content of a specific hook as a string. ```APIDOC ## Hooks::get(string $name) ### Description Returns the content of the specified hook file. ### Parameters - **name** (string) - Required - The name of the hook (e.g., 'pre-receive'). ### Returns - **string** - The content of the hook file. ### Exceptions - **InvalidArgumentException** - Thrown if the hook does not exist. ``` -------------------------------- ### Retrieve Collections of References Source: https://github.com/gitonomy/gitlib/blob/main/doc/references.md Fetch lists of branches, tags, or all references from the ReferenceBag. ```php $branches = $references->getBranches(); $localBranches = $references->getLocalBranches(); $remoteBranches = $references->getRemoteBranches(); $tags = $references->getTags(); $all = $references->getAll(); ``` -------------------------------- ### Checking for hook existence Source: https://github.com/gitonomy/gitlib/blob/main/doc/hooks.md Verify if a specific hook exists in the repository. ```php $hooks->has('pre-receive'); // a boolean indicating presence ``` -------------------------------- ### Iterate over blame lines in PHP Source: https://github.com/gitonomy/gitlib/blob/main/doc/blame.md Retrieves blame information for a file and iterates through each line to access content and commit metadata. ```php $blame = $repository->getBlame('master', 'README.md'); foreach ($blame->getLines() as $lineNumber => $line) { $commit = $line->getCommit(); echo $lineNumber.': '.$line->getContent().' - '.$commit->getAuthorName().PHP_EOL; } ``` -------------------------------- ### Access Repository HEAD Source: https://github.com/gitonomy/gitlib/blob/main/doc/repository.md Retrieve the current HEAD or commit, and check if the repository is in a detached state. ```php $head = $repository->getHead(); // Commit or Reference $head = $repository->getHeadCommit(); // Commit if ($repository->isHeadDetached()) { echo 'Sorry man'.PHP_EOL; } ``` -------------------------------- ### Gitonomy\Git\Blob::isText / isBinary Source: https://github.com/gitonomy/gitlib/blob/main/doc/blob.md Methods to determine if the blob content is text or binary. ```APIDOC ## Methods: isText / isBinary ### Description Checks the content type of the blob. ### Signatures `bool isText()` `bool isBinary()` ### Example ```php if ($blob->isText()) { echo $blob->getContent(); } elseif ($blob->isBinary()) { echo 'File is binary'; } ``` ``` -------------------------------- ### Retrieve a revision from a repository Source: https://github.com/gitonomy/gitlib/blob/main/doc/revision.md Use the getRevision method on a Repository object to fetch a specific revision. ```php $revision = $repository->getRevision('master@{2 days ago}'); ``` -------------------------------- ### Repository::getBlame Source: https://github.com/gitonomy/gitlib/blob/main/doc/blame.md Retrieves the blame information for a specific file at a given revision. ```APIDOC ## Repository::getBlame ### Description Retrieves a Blame object for a specified file path and revision. ### Signature `$repository->getBlame(string $revision, string $filePath)` ### Returns - **Blame** - The blame object containing file line information. ``` -------------------------------- ### Access Reference Metadata Source: https://github.com/gitonomy/gitlib/blob/main/doc/references.md Retrieve commit information, hashes, or last modification details from a Branch or Tag object. ```php // Get the associated commit $commit = $master->getCommit(); // Get the commit hash $hash = $master->getCommitHash(); // Get the last modification $lastModification = $master->getLastModification(); ``` -------------------------------- ### Retrieve a Blob from a Repository Source: https://github.com/gitonomy/gitlib/blob/main/doc/blob.md Access a blob object using its hash identifier from a repository instance. ```php $repository = new Gitonomy\Git\Repository('/path/to/repository'); $blob = $repository->getBlob('a7c8d2b4'); ``` -------------------------------- ### Branch and Tag Object Methods Source: https://github.com/gitonomy/gitlib/blob/main/doc/references.md Methods available on Branch and Tag objects to retrieve reference information. ```APIDOC ## Branch/Tag Object API ### Description Methods available on objects returned by getBranch() or getTag(). ### Methods - **getCommit()**: Returns the associated Commit object. - **getCommitHash()**: Returns the commit hash string. - **getLastModification()**: Returns the last modification information. - **delete()**: Deletes the branch or tag reference. ``` -------------------------------- ### Iterate Over Modified Files Source: https://github.com/gitonomy/gitlib/blob/main/doc/diff.md Retrieve a list of File objects from a Diff instance to inspect file metadata and modification details. ```php $files = $diff->getFiles(); echo sprintf('%s files modified%s', count($files), PHP_EOL); foreach ($files as $fileDiff) { echo sprintf('Old name: (%s) %s%s', $fileDiff->getOldMode(), $fileDiff->getOldName(), PHP_EOL); echo sprintf('New name: (%s) %s%s', $fileDiff->getNewMode(), $fileDiff->getNewName(), PHP_EOL); } ``` -------------------------------- ### Resolve file path Source: https://github.com/gitonomy/gitlib/blob/main/doc/tree.md Directly access a sub-file or sub-directory within a tree using a path string. ```php $source = $tree->resolvePath('src/Gitonomy/Git'); $source instanceof Tree; ``` -------------------------------- ### Repository::getLog Source: https://github.com/gitonomy/gitlib/blob/main/doc/log.md Retrieves a Log object from a repository, optionally filtered by branch, file path, offset, and limit. ```APIDOC ## Repository::getLog ### Description Retrieves a Log object representing the commit history of a repository. Supports filtering by branch, specific files, and pagination. ### Signature `getLog(string $branch = null, string|array $path = null, int $offset = 0, int $limit = 30)` ### Parameters - **$branch** (string) - Optional - The branch name to retrieve logs from. - **$path** (string|array) - Optional - A single file path or an array of file paths to filter the log. - **$offset** (int) - Optional - The number of commits to skip. - **$limit** (int) - Optional - The maximum number of commits to return. ``` -------------------------------- ### Retrieve Author and Committer Information Source: https://github.com/gitonomy/gitlib/blob/main/doc/commit.md Access identity and timestamp details for both the author and the committer. ```php // Author $commit->getAuthorName(); $commit->getAuthorEmail(); $commit->getAuthorDate(); // returns a DateTime object // Committer $commit->getCommitterName(); $commit->getCommitterEmail(); $commit->getCommitterDate(); // returns a DateTime object ``` -------------------------------- ### Compute a Diff from Repository or Log Source: https://github.com/gitonomy/gitlib/blob/main/doc/diff.md Generate a Diff object by specifying a revision range from either a Repository instance or a Log object. ```php $diff = $repository->getDiff('master@{2 days ago}..master'); ``` ```php $log = $repository->getLog('master@{2 days ago}..master'); $diff = $log->getDiff(); ``` -------------------------------- ### Reading hook content Source: https://github.com/gitonomy/gitlib/blob/main/doc/hooks.md Retrieve the content of a specific hook by name. ```php $content = $hooks->get('pre-receive'); // returns a string ``` -------------------------------- ### Access File Changes and Line Data Source: https://github.com/gitonomy/gitlib/blob/main/doc/diff.md Iterate through FileChange objects to process line-level diff data and retrieve line number ranges. ```php $changes = $file->getChanges(); foreach ($changes as $change) { foreach ($lines as $data) { list ($type, $line) = $data; if ($type === FileChange::LINE_CONTEXT) { echo ' '.$line.PHP_EOL; } elseif ($type === FileChange::LINE_ADD) { echo '+'.$line.PHP_EOL; } else { echo '-'.$line.PHP_EOL; } } } ``` ```php echo sprintf('Previously from line %s to %s%s', $change->getOldRangeStart(), $change->getOldRangeEnd(), PHP_EOL); echo sprintf('Now from line %s to %s%s', $change->getNewRangeStart(), $change->getNewRangeEnd(), PHP_EOL); ``` -------------------------------- ### Recursively display tree entries Source: https://github.com/gitonomy/gitlib/blob/main/doc/tree.md Iterate through tree entries using getEntries and handle nested Tree objects recursively. ```php function displayTree(Tree $tree, $indent = 0) { $indent = str_repeat(' ', $indent); foreach ($tree->getEntries() as $name => $data) { list($mode, $entry) = $data; if ($entry instanceof Tree) { echo $indent.$name.'/'.PHP_EOL; displayTree($tree, $indent + 1); } else { echo $indent.$name.PHP_EOL; } } } displayTree($commit->getTree()); ``` -------------------------------- ### Hooks::setSymlink Source: https://github.com/gitonomy/gitlib/blob/main/doc/hooks.md Creates a symlink for a hook. ```APIDOC ## Hooks::setSymlink(string $name, string $path) ### Description Creates a symlink to an existing file for the specified hook. ### Parameters - **name** (string) - Required - The name of the hook. - **path** (string) - Required - The absolute path to the file to link. ### Exceptions - **LogicException** - Thrown if the hook already exists. - **RuntimeException** - Thrown if an error occurs during symlink creation. ``` -------------------------------- ### Blame::getLine Source: https://github.com/gitonomy/gitlib/blob/main/doc/blame.md Retrieves a specific line by its line number. ```APIDOC ## Blame::getLine ### Description Access a specific line directly using its line number. ### Signature `$blame->getLine(int $lineNumber)` ### Parameters - **lineNumber** (int) - The line number to retrieve. ### Returns - **Line** - The requested Line object. ``` -------------------------------- ### Admin::cloneBranchTo Source: https://github.com/gitonomy/gitlib/blob/main/doc/admin.md Clones a specific branch of a repository to a local path. ```APIDOC ## Admin::cloneBranchTo ### Description Clones a repository and checks out a specific branch. ### Signature `Gitonomy\Git\Admin::cloneBranchTo(string $path, string $url, string $branch, bool $bare = true)` ### Parameters - **$path** (string) - Required - The local destination path. - **$url** (string) - Required - The remote repository URL. - **$branch** (string) - Required - The branch name to clone. - **$bare** (bool) - Optional - Whether to create a bare repository. Defaults to true. ``` -------------------------------- ### Group blame lines by commit in PHP Source: https://github.com/gitonomy/gitlib/blob/main/doc/blame.md Illustrates the structure returned by the getGroupedLines method for displaying lines grouped by their associated commit. ```php $blame = array( array(Commit, array(1 => Line, 2 => Line, 3 => Line)), array(Commit, array(4 => Line)), array(Commit, array(5 => Line, 6 => Line)) ) ``` -------------------------------- ### Clone a specific branch Source: https://github.com/gitonomy/gitlib/blob/main/doc/admin.md Clone a repository and check out a specific branch. In non-bare repositories, the branch is automatically checked out. ```php // Clone to a bare repository $repository = Gitonomy\Git\Admin::cloneBranchTo('/tmp/gitlib', 'https://github.com/gitonomy/gitlib.git', 'a-branch'); // Clone to a non-bare repository $repository = Gitonomy\Git\Admin::cloneBranchTo('/tmp/gitlib', 'https://github.com/gitonomy/gitlib.git', 'a-branch', false); ``` -------------------------------- ### Access a Git branch Source: https://github.com/gitonomy/gitlib/blob/main/doc/branch.md Retrieves a branch object from a repository instance using the reference manager. ```php $repository = new Gitonomy\Git\Repository('/path/to/repository'); $branch = $repository->getReferences()->getBranch('master'); ``` -------------------------------- ### Check Blob File Type Source: https://github.com/gitonomy/gitlib/blob/main/doc/blob.md Test whether a blob contains text or binary data. ```php if ($blob->isText()) { echo $blob->getContent(), PHP_EOL; } elseif ($blob->isBinary()) { echo 'File is binary', PHP_EOL; } ``` -------------------------------- ### Line Object Methods Source: https://github.com/gitonomy/gitlib/blob/main/doc/blame.md Methods available on a Line object to retrieve content and commit metadata. ```APIDOC ## Line Object Methods ### Description Methods to access data from a Line object. ### Methods - **getCommit()**: Returns the Commit object associated with the line. - **getContent()**: Returns the text content of the line. ``` -------------------------------- ### Access a commit log Source: https://github.com/gitonomy/gitlib/blob/main/doc/revision.md Retrieve a Log object from a revision using offset and limit parameters. ```php // Returns 100 lasts commits $log = $revision->getLog(null, 100); ``` -------------------------------- ### Retrieve root tree from commit Source: https://github.com/gitonomy/gitlib/blob/main/doc/tree.md Access the root tree object associated with a specific commit. ```php $tree = $commit->getTree(); ``` -------------------------------- ### Hooks::has Source: https://github.com/gitonomy/gitlib/blob/main/doc/hooks.md Checks if a specific hook exists in the repository. ```APIDOC ## Hooks::has(string $name) ### Description Checks for the presence of a hook file. ### Parameters - **name** (string) - Required - The name of the hook. ### Returns - **boolean** - True if the hook exists, false otherwise. ``` -------------------------------- ### Commit Methods Source: https://github.com/gitonomy/gitlib/blob/main/doc/commit.md Methods available on the Gitonomy\Git\Commit object for accessing commit data. ```APIDOC ## Commit Methods ### Parent Access - `getParentHashes()`: Returns an array of parent commit hashes. - `getParents()`: Returns an array of parent Commit objects. ### Tree Access - `getTreeHash()`: Returns the hash of the associated tree. - `getTree()`: Returns the associated Tree object. ### Author & Committer Info - `getAuthorName()`, `getAuthorEmail()`, `getAuthorDate()`: Access author details. - `getCommitterName()`, `getCommitterEmail()`, `getCommitterDate()`: Access committer details. ### Message Access - `getMessage()`: Returns the full commit message. - `getShortMessage(int $length, bool $cut, string $separator)`: Returns a truncated message. - `getSubjectMessage()`: Returns the first line of the message. - `getBodyMessage()`: Returns the body of the message. ### Diff & History - `getDiff()`: Returns the Diff object for the commit. - `getLastModification(string $path)`: Returns the last commit that modified the specified file. - `getIncludingBranches(bool $local, bool $remote)`: Returns branches containing this commit. ``` -------------------------------- ### Retrieve Blob Mimetype Source: https://github.com/gitonomy/gitlib/blob/main/doc/blob.md Determine the mimetype of a blob using the PHP finfo extension. ```php echo $blob->getMimetype(); ``` -------------------------------- ### Access Commit Tree Source: https://github.com/gitonomy/gitlib/blob/main/doc/commit.md Retrieve the tree hash or the tree object associated with a commit. ```php // Returns the tree hash $tree = $commit->getTreeHash(); // Returns the tree object $tree = $commit->getTree(); ``` -------------------------------- ### Resolve References from Commit Source: https://github.com/gitonomy/gitlib/blob/main/doc/references.md Identify branches or tags associated with a specific commit object or hash. ```php $branches = $references->resolveBranches($commit); $tags = $references->resolveTags($commit); // Resolve branches and tags $all = $references->resolve($commit); ``` -------------------------------- ### Access Commit Parents Source: https://github.com/gitonomy/gitlib/blob/main/doc/commit.md Retrieve parent hashes or full commit objects for a given commit. ```php // Access parent hashes $hashes = $commit->getParentHashes(); // Access parent commit objects $commits = $commit->getParents(); ``` -------------------------------- ### Gitonomy\Git\Blob::getMimetype Source: https://github.com/gitonomy/gitlib/blob/main/doc/blob.md Retrieves the mimetype of the blob using the finfo extension. ```APIDOC ## Method: getMimetype ### Description Returns the mimetype of the blob. ### Signature `string getMimetype()` ### Example ```php echo $blob->getMimetype(); ``` ``` -------------------------------- ### Check branch type Source: https://github.com/gitonomy/gitlib/blob/main/doc/branch.md Determines whether a branch is local or remote. ```php $branch->isLocal(); $branch->isRemote(); ``` -------------------------------- ### Diff::getFiles Source: https://github.com/gitonomy/gitlib/blob/main/doc/diff.md Retrieves a list of modified files from a Diff object. ```APIDOC ## Diff::getFiles() ### Description Returns an array of File objects representing modifications for each file in the diff. ### Example ```php $files = $diff->getFiles(); foreach ($files as $fileDiff) { echo $fileDiff->getOldName(); } ``` ``` -------------------------------- ### Log::getDiff Source: https://github.com/gitonomy/gitlib/blob/main/doc/diff.md Retrieves a diff object from a log instance. ```APIDOC ## Log::getDiff() ### Description Accesses the diff associated with a log object. ### Example ```php $log = $repository->getLog('master@{2 days ago}..master'); $diff = $log->getDiff(); ``` ``` -------------------------------- ### Removing a hook Source: https://github.com/gitonomy/gitlib/blob/main/doc/hooks.md Delete a hook from the repository. ```php $hooks->remove('pre-receive'); ``` -------------------------------- ### Retrieve Commit Diff Source: https://github.com/gitonomy/gitlib/blob/main/doc/commit.md Access the Diff object for a commit, which varies based on the number of parents. ```php $diff = $commit->getDiff(); ``` -------------------------------- ### Hooks::remove Source: https://github.com/gitonomy/gitlib/blob/main/doc/hooks.md Removes a hook from the repository. ```APIDOC ## Hooks::remove(string $name) ### Description Deletes the specified hook file from the repository. ### Parameters - **name** (string) - Required - The name of the hook to remove. ``` -------------------------------- ### Count Commits Source: https://github.com/gitonomy/gitlib/blob/main/doc/log.md Retrieves the total number of commits in the log using the countCommits method or the Countable interface. ```php echo sprintf('This log contains %s commits%s', $log->countCommits(), PHP_EOL); // Countable interface echo sprintf('This log contains %s commits%s', count($log), PHP_EOL); ``` -------------------------------- ### Repository::getDiff Source: https://github.com/gitonomy/gitlib/blob/main/doc/diff.md Computes a diff for a given git revision range from a repository object. ```APIDOC ## Repository::getDiff(string $revision) ### Description Computes a diff based on a specified git revision or range. ### Parameters - **revision** (string) - Required - A git revision (e.g., '2bc7a8') or range (e.g., '2bc7a8..ff4c21b'). ### Example ```php $diff = $repository->getDiff('master@{2 days ago}..master'); ``` ``` -------------------------------- ### Access Commit Messages Source: https://github.com/gitonomy/gitlib/blob/main/doc/commit.md Retrieve full, short, subject, or body messages from a commit. ```php $commit->getMessage(); ``` ```php $commit->getShortMessage(); ``` ```php $commit->getShortMessage(45, true, '.'); ``` ```php // The first line $commit->getSubjectMessage(); // The body (rest of the message) $commit->getBodyMessage(); ``` -------------------------------- ### Branch Reference Retrieval Source: https://github.com/gitonomy/gitlib/blob/main/doc/branch.md Retrieves a specific branch object from a repository instance. ```APIDOC ## Method: getBranch ### Description Retrieves a branch object by its name from the repository references. ### Signature `$repository->getReferences()->getBranch(string $name)` ### Parameters - **name** (string) - Required - The name of the branch (e.g., 'master'). ``` -------------------------------- ### Resolve a revision to a commit Source: https://github.com/gitonomy/gitlib/blob/main/doc/revision.md Convert a revision object into a commit object. ```php $commit = $revision->getCommit(); ``` -------------------------------- ### Disable Debug Mode Source: https://github.com/gitonomy/gitlib/blob/main/doc/repository.md Set debug to false to prevent RuntimeExceptions on non-zero git exit codes. ```php $repository = new Repository('/tmp/foo', ['debug' => false, 'logger' => $logger]); ``` -------------------------------- ### Access a specific blame line in PHP Source: https://github.com/gitonomy/gitlib/blob/main/doc/blame.md Retrieves a single line object from the blame result by its line number. ```php $line = $blame->getLine(32); ``` -------------------------------- ### Log::countCommits Source: https://github.com/gitonomy/gitlib/blob/main/doc/log.md Methods to retrieve the total count of commits within the log instance. ```APIDOC ## Log::countCommits ### Description Returns the total number of commits in the log. The object also implements the Countable interface. ### Usage `$log->countCommits();` `count($log);` ``` -------------------------------- ### Branch Type Identification Source: https://github.com/gitonomy/gitlib/blob/main/doc/branch.md Methods to check the type of a branch reference. ```APIDOC ## Method: isLocal ### Description Checks if the branch is a local branch. ### Signature `$branch->isLocal()` ## Method: isRemote ### Description Checks if the branch is a remote branch. ### Signature `$branch->isRemote()` ``` -------------------------------- ### Blame::getGroupedLines Source: https://github.com/gitonomy/gitlib/blob/main/doc/blame.md Retrieves lines grouped by their associated commit. ```APIDOC ## Blame::getGroupedLines ### Description Returns an array where lines are grouped by the commit they belong to. ### Signature `$blame->getGroupedLines()` ### Returns - **array** - An array of arrays, where each sub-array contains a Commit object and an array of associated Line objects. ``` -------------------------------- ### Find Branches Containing a Commit Source: https://github.com/gitonomy/gitlib/blob/main/doc/commit.md Check which local or remote branches include a specific commit. ```php $branches = $commit->getIncludingBranches($includeLocalBranches, $includeRemoteBranches); $localBranches = $commit->getIncludingBranches(true, false); $remoteBranches = $commit->getIncludingBranches(false, true); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.