/**
* Load 7 char abbreviated hash for commit from the system (file or exec).
*
* Look for a file RECENT_COMMIT if a Git post-commit hook exists and created it
* otherwise call Git using shell_exec().
*
* @param string $class_name
*
* @return null
*/
static function load_recent_commit($class_name)
{
$filepath = self::_get_recent_commit_file($class_name);
$recent_commit = WPLib::is_found($filepath) ? trim(WPLib::get_contents($filepath)) : null;
if (is_null($recent_commit) && WPLib::is_development()) {
/**
* Call `git log` via exec()
*/
$root_dir = self::_get_class_root_dir($class_name);
$command = "cd {$root_dir} && git log -1 --oneline && cd -";
exec($command, $output, $return_value);
if (0 === $return_value && isset($output[0])) {
/**
* If no git repo in dir, $return_value==127 and $output==array()
* If no git on system, $return_value==128 and $output==array()
* If good, first 7 chars of $output[0] has abbreviated hash for commit
*/
$recent_commit = substr($output[0], 0, 7);
}
}
return $recent_commit;
}