getHeadCommit() public method

Returns the HEAD resolved as a commit.
public getHeadCommit ( ) : Gitonomy\Git\Commit | null
return Gitonomy\Git\Commit | null returns a Commit or ``null`` if repository is empty
示例#1
0
文件: GitDown.php 项目: skizu/gitdown
 /**
  * Create a new GitDown parser instance.
  *
  * @param $directory string
  * @throws RuntimeException if GitRuntimeException caught
  * @throws InvalidArgumentException if GitInvalidArgumentException caught
  */
 public function __construct($directory)
 {
     try {
         $this->repository = new Repository($directory);
         $this->commit = $this->repository->getHeadCommit();
     } catch (GitInvalidArgumentException $e) {
         throw new InvalidArgumentException($e->getMessage());
     } catch (GitRuntimeException $e) {
         throw new RuntimeException($e->getMessage());
     }
 }
 /**
  * @throws \DebugBar\DebugBarException
  */
 public function boot()
 {
     $debugbar = $this->app['debugbar'];
     if ($debugbar instanceof LaravelDebugbar && $debugbar->isEnabled()) {
         /**
          * CodeCollector获取代码提交和版本信息
          */
         $codeCollector = new MessagesCollector('code');
         $codeCollector->addMessage('enviroment:' . $this->app->environment());
         //package "sebastian/version": "1.*"  required
         if (class_exists(Version::class)) {
             $version = static::appVersion($this->app['config']->get('app.version'));
             $codeCollector->addMessage('base path:' . base_path());
             $codeCollector->addMessage("version:\n" . $version);
         }
         if (class_exists(Repository::class)) {
             $repository = new \Gitonomy\Git\Repository(base_path());
             $head = $repository->getHeadCommit();
             $log = $head->getLog(null, null, 5);
             $commits = array();
             foreach ($log->getCommits() as $commit) {
                 $commits[] = $this->commitMessageArray($commit);
             }
             $codeCollector->addMessage("current commit:\n" . $head->getRevision(), 'HEAD');
             $codeCollector->addMessage($commits, 'git-log');
         }
         $debugbar->addCollector($codeCollector);
         /**
          * ServerCollector获取服务器信息
          */
         $serverCollector = new MessagesCollector('sever');
         $serverCollector->addMessage(php_uname(), 'uname');
         $serverCollector->addMessage("sapi_name:" . php_sapi_name(), 'phpinfo');
         $serverCollector->addMessage("PHP version:" . PHP_VERSION, 'phpinfo');
         $serverCollector->addMessage("Zend_Version:" . zend_version(), 'phpinfo');
         $serverCollector->addMessage(sys_getloadavg(), 'load');
         $debugbar->addCollector($serverCollector);
     }
 }
 /**
  * @return string The Hash of the latest Commit.
  */
 public function getHashOfLatestCommit()
 {
     $head = $this->_repository->getHeadCommit();
     return $head->getHash();
 }