PHP code example of antogno / gitinfo

1. Go to this page and download the library: Download antogno/gitinfo library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

antogno / gitinfo example snippets


use antogno\GitInfo\GitInfo;

$GitInfo = new GitInfo();

$GitInfo->getGitVersion();
// For example: string(6) "2.40.0"

$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" }

$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" }

$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" }

$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" }

$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" }

$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" }

$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" }

$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)

$GitInfo->getCurrentCommitAuthor();

$GitInfo->getAuthor('[email protected]', 'antogno');

$GitInfo->getAuthor('', 'antogno');

$GitInfo->getAuthor('[email protected]');

$GitInfo->getAuthors();

use antogno\GitInfo\Resources\AuthorResource;

$Author = new AuthorResource('[email protected]', 'antogno');

$Author = new AuthorResource('', 'antogno');

$Author = new AuthorResource('[email protected]');

$Author->getName();
// For example: string(7) "antogno"

$Author->getEmail();
// For example: string(24) "[email protected]"

$Author->getCommits();

$GitInfo->hasBranch('master');
// For example: bool(true)

$GitInfo->hasBranch('MASTER');
// For example: bool(false)

$GitInfo->getCurrentBranch();

$GitInfo->getBranch('master');

$GitInfo->getBranches();

use antogno\GitInfo\Resources\BranchResource;

$Branch = new BranchResource('master');

$Branch->getName();
// For example: string(6) "master"

$Branch->getLastCommit();

$GitInfo->hasCommit('ed8f9325485f108ddafe3890dc4b13be07aa13cb');
// For example: bool(true)

$GitInfo->hasCommit('ed8f932');
// For example: bool(true)

$GitInfo->getCurrentCommit();

$GitInfo->getCommit('ed8f9325485f108ddafe3890dc4b13be07aa13cb');

$GitInfo->getCommit('ed8f932');

$GitInfo->getCommits();

use antogno\GitInfo\Resources\CommitResource;

$Commit = new CommitResource('ed8f9325485f108ddafe3890dc4b13be07aa13cb');

$Commit = new CommitResource('ed8f932');

$Commit->getLongHash();
// For example: string(40) "ed8f9325485f108ddafe3890dc4b13be07aa13cb"

$Commit->getShortHash();
// For example: string(7) "ed8f932"

$Commit->getMessage();
// For example: string(14) "Initial commit"

$Commit->getDate();

$Commit->getAuthor();

$GitInfo->hasTag('v1.0.0');
// For example: bool(true)

$GitInfo->hasTag('V1.0.0');
// For example: bool(false)

$GitInfo->getCurrentTag();

$GitInfo->getTag('v1.0.0');

$GitInfo->getTags();

use antogno\GitInfo\Resources\TagResource;

$Tag = new TagResource('v1.0.0');

$Tag->getName();
// For example: string(6) "v1.0.0"

$Tag->getLastCommit();

$GitInfo->hasRemote('origin');
// For example: bool(true)

$GitInfo->hasRemote('ORIGIN');
// For example: bool(false)

$GitInfo->getCurrentRemote();

$GitInfo->getRemote('origin');

$GitInfo->getRemotes();

use antogno\GitInfo\Resources\RemoteResource;

$Remote = new RemoteResource('origin');

$Remote->getName();
// For example: string(6) "origin"

$Remote->getUrl();
// For example: string(38) "https://github.com/antogno/gitinfo.git"