-
-
Save baskan/5635594 to your computer and use it in GitHub Desktop.
made compatible with Laravel and fixed "message" array existance error.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Orginal Author: Ngo Minh Nam | |
function git_commits() | |
{ | |
$dir = base_path(); //for using with laravel | |
$output = array(); | |
chdir($dir); | |
exec("git log",$output); | |
$history = array(); | |
//dd($output); | |
foreach($output as $line){ | |
if(strpos($line, 'commit')===0){ | |
if(!empty($commit)){ | |
array_push($history, $commit); | |
unset($commit); | |
} | |
$commit['hash'] = substr($line, strlen('commit')); | |
} | |
else if(strpos($line, 'Author')===0){ | |
$commit['author'] = substr($line, strlen('Author:')); | |
} | |
else if(strpos($line, 'Date')===0){ | |
$commit['date'] = substr($line, strlen('Date:')); | |
} | |
else{ | |
if(array_key_exists('message', $commit)) | |
{ | |
$commit['message'] .= $line; | |
}else{ | |
$commit['message'] = $line; | |
} | |
} | |
} | |
return $history; | |
} | |
//example: | |
print_r(git_commits()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment