GitInfo is a tool that lets you get information about the current Git repository.
Use the dependency manager Composer to install GitInfo.
$ composer require antogno/gitinfo
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" }
Whether the given author exists or not:
$GitInfo->hasAuthor('[email protected]', 'antogno');
// For example: bool(true)
$GitInfo->hasAuthor('', 'johndoe');
// For example: bool(false)
$GitInfo->hasAuthor('[email protected]', 'ANTOGNO');
// For example: bool(true)
Get the author of the current commit:
$GitInfo->getCurrentCommitAuthor();
Get the given author, if exists:
$GitInfo->getAuthor('[email protected]', 'antogno');
$GitInfo->getAuthor('', 'antogno');
$GitInfo->getAuthor('[email protected]');
Get the authors list:
$GitInfo->getAuthors();
Each of the previous three methods returns an AuthorResource
object (or a list of such).
use antogno\GitInfo\Resources\AuthorResource;
$Author = new AuthorResource('[email protected]', 'antogno');
$Author = new AuthorResource('', 'antogno');
$Author = new AuthorResource('[email protected]');
Get the author name:
$Author->getName();
// For example: string(7) "antogno"
Get the author email:
$Author->getEmail();
// For example: string(24) "[email protected]"
Get the author commits (CommitResource
list):
$Author->getCommits();
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).
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();
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).
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();
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).
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();
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).
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"
GitInfo is licensed under the terms of the Creative Commons Zero v1.0 Universal license.
For more information, see the Creative Commons website.