antogno / gitinfo
GitInfo is a tool that lets you get information about the current Git repository
Requires
- php: >=7.0.0
This package is auto-updated.
Last update: 2024-12-26 17:02:28 UTC
README
GitInfo is a tool that lets you get information about the current Git repository.
Installation
Use the dependency manager Composer to install GitInfo.
$ composer require antogno/gitinfo
Usage
use antogno\GitInfo\GitInfo; $GitInfo = new GitInfo();
Get the Git version:
$GitInfo->getGitVersion(); // For example: string(6) "2.40.0"
Get any deleted file:
$GitInfo->getDeletedFiles(false); // For example: array(2) { [0]=> string(13) "deleted_1.php" [1]=> string(13) "deleted_2.php" } $GitInfo->getDeletedFiles(true); // For example: array(2) { [0]=> string(36) "/Users/antogno/gitinfo/deleted_1.php" [1]=> string(36) "/Users/antogno/gitinfo/deleted_2.php" }
Get any modified file:
$GitInfo->getModifiedFiles(false); // For example: array(2) { [0]=> string(14) "modified_1.php" [1]=> string(14) "modified_2.php" } $GitInfo->getModifiedFiles(true); // For example: array(2) { [0]=> string(37) "/Users/antogno/gitinfo/modified_1.php" [1]=> string(37) "/Users/antogno/gitinfo/modified_2.php" }
Get any renamed file:
$GitInfo->getRenamedFiles(false); // For example: array(1) { ["old_name.php"]=> string(12) "new_name.php" } $GitInfo->getRenamedFiles(true); // For example: array(1) { ["/Users/antogno/gitinfo/old_name.php"]=> string(35) "/Users/antogno/gitinfo/new_name.php" }
Get any unmerged file:
$GitInfo->getUnmergedFiles(false); // For example: array(2) { [0]=> string(14) "unmerged_1.php" [1]=> string(14) "unmerged_2.php" } $GitInfo->getUnmergedFiles(true); // For example: array(2) { [0]=> string(37) "/Users/antogno/gitinfo/unmerged_1.php" [1]=> string(37) "/Users/antogno/gitinfo/unmerged_2.php" }
Get any untracked file:
$GitInfo->getUntrackedFiles(false); // For example: array(2) { [0]=> string(15) "untracked_1.php" [1]=> string(15) "untracked_2.php" } $GitInfo->getUntrackedFiles(true); // For example: array(2) { [0]=> string(38) "/Users/antogno/gitinfo/untracked_1.php" [1]=> string(38) "/Users/antogno/gitinfo/untracked_2.php" }
Get any staged file:
$GitInfo->getStagedFiles(false); // For example: array(2) { [0]=> string(12) "modified.php" [1]=> string(11) "deleted.php" } $GitInfo->getStagedFiles(true); // For example: array(2) { [0]=> string(35) "/Users/antogno/gitinfo/modified.php" [1]=> string(34) "/Users/antogno/gitinfo/deleted.php" }
Get any unstaged file:
$GitInfo->getUnstagedFiles(false); // For example: array(2) { [0]=> string(12) "modified.php" [1]=> string(11) "deleted.php" } $GitInfo->getUnstagedFiles(true); // For example: array(2) { [0]=> string(35) "/Users/antogno/gitinfo/modified.php" [1]=> string(34) "/Users/antogno/gitinfo/deleted.php" }
Author
Whether the given author exists or not:
$GitInfo->hasAuthor('tonio.granaldi@gmail.com', 'antogno'); // For example: bool(true) $GitInfo->hasAuthor('', 'johndoe'); // For example: bool(false) $GitInfo->hasAuthor('TONIO.GRANALDI@GMAIL.COM', 'ANTOGNO'); // For example: bool(true)
Get the author of the current commit:
$GitInfo->getCurrentCommitAuthor();
Get the given author, if exists:
$GitInfo->getAuthor('tonio.granaldi@gmail.com', 'antogno'); $GitInfo->getAuthor('', 'antogno'); $GitInfo->getAuthor('TONIO.GRANALDI@GMAIL.COM');
Get the authors list:
$GitInfo->getAuthors();
Each of the previous three methods returns an AuthorResource
object (or a list of such).
AuthorResource
use antogno\GitInfo\Resources\AuthorResource; $Author = new AuthorResource('tonio.granaldi@gmail.com', 'antogno'); $Author = new AuthorResource('', 'antogno'); $Author = new AuthorResource('TONIO.GRANALDI@GMAIL.COM');
Get the author name:
$Author->getName(); // For example: string(7) "antogno"
Get the author email:
$Author->getEmail(); // For example: string(24) "tonio.granaldi@gmail.com"
Get the author commits (CommitResource
list):
$Author->getCommits();
Branch
Whether the given branch exists or not:
$GitInfo->hasBranch('master'); // For example: bool(true) $GitInfo->hasBranch('MASTER'); // For example: bool(false)
Get the current branch:
$GitInfo->getCurrentBranch();
Get the given branch, if exists:
$GitInfo->getBranch('master');
Get the branches list:
$GitInfo->getBranches();
Each of the previous three methods returns a BranchResource
object (or a list of such).
BranchResource
use antogno\GitInfo\Resources\BranchResource; $Branch = new BranchResource('master');
Get the author name:
$Branch->getName(); // For example: string(6) "master"
Get the branch last commit (CommitResource
):
$Branch->getLastCommit();
Commit
Whether a commit with the given hash exists or not:
$GitInfo->hasCommit('ed8f9325485f108ddafe3890dc4b13be07aa13cb'); // For example: bool(true) $GitInfo->hasCommit('ed8f932'); // For example: bool(true)
Get the current commit:
$GitInfo->getCurrentCommit();
Get the given commit, if exists:
$GitInfo->getCommit('ed8f9325485f108ddafe3890dc4b13be07aa13cb'); $GitInfo->getCommit('ed8f932');
Get the commits list:
$GitInfo->getCommits();
Each of the previous three methods returns a CommitResource
object (or a list of such).
CommitResource
use antogno\GitInfo\Resources\CommitResource; $Commit = new CommitResource('ed8f9325485f108ddafe3890dc4b13be07aa13cb'); $Commit = new CommitResource('ed8f932');
Get the long commit hash:
$Commit->getLongHash(); // For example: string(40) "ed8f9325485f108ddafe3890dc4b13be07aa13cb"
Get the short commit hash:
$Commit->getShortHash(); // For example: string(7) "ed8f932"
Get the commit message:
$Commit->getMessage(); // For example: string(14) "Initial commit"
Get the commit date (DateTime
):
$Commit->getDate();
Get the commit author (AuthorResource
):
$Commit->getAuthor();
Tag
Whether the given tag exists or not:
$GitInfo->hasTag('v1.0.0'); // For example: bool(true) $GitInfo->hasTag('V1.0.0'); // For example: bool(false)
Get the current tag, if in a tag:
$GitInfo->getCurrentTag();
Get the given tag, if exists:
$GitInfo->getTag('v1.0.0');
Get the tags list:
$GitInfo->getTags();
Each of the previous three methods returns a TagResource
object (or a list of such).
TagResource
use antogno\GitInfo\Resources\TagResource; $Tag = new TagResource('v1.0.0');
Get the tag name:
$Tag->getName(); // For example: string(6) "v1.0.0"
Get the tag last commit (CommitResource
):
$Tag->getLastCommit();
Remote
Whether the given remote exists or not:
$GitInfo->hasRemote('origin'); // For example: bool(true) $GitInfo->hasRemote('ORIGIN'); // For example: bool(false)
Get the remote from which the current branch is tracking:
$GitInfo->getCurrentRemote();
Get the given remote, if exists:
$GitInfo->getRemote('origin');
Get the remotes list:
$GitInfo->getRemotes();
Each of the previous three methods returns a RemoteResource
object (or a list of such).
RemoteResource
use antogno\GitInfo\Resources\RemoteResource; $Remote = new RemoteResource('origin');
Get the remote name:
$Remote->getName(); // For example: string(6) "origin"
Get the remote URL:
$Remote->getUrl(); // For example: string(38) "https://github.com/antogno/gitinfo.git"
License
GitInfo is licensed under the terms of the Creative Commons Zero v1.0 Universal license.
For more information, see the Creative Commons website.