Exemplo n.º 1
0
 /**
  * @return null|string
  */
 private function readMercurial()
 {
     $hgDir = Path::combine($this->repositoryRoot, '.hg');
     if (!is_dir($hgDir) || !OS::hasBinary('hg')) {
         return null;
     }
     $hg = Exec::create('hg', '--repository', $this->repositoryRoot);
     // Removes everything but the tag if distance is zero.
     $hg->run('log', '-r', '.', '--template', '{latesttag}{sub(\'^-0-m.*\', \'\', \'-{latesttagdistance}-m{node|short}\')}');
     $tag = Dot::get($hg->getOutput(), 0);
     // Actual null if no lines were returned or `hg log` returned actual "null".
     // Either way, need to fall back to the revision id.
     if ($tag === null || $tag === 'null' || Strings::startsWith($tag, 'null-')) {
         $hg->run('id', '-i');
         $tag = Dot::get($hg->getOutput(), 0);
         // Remove 'dirty' plus from revision id
         $tag = rtrim($tag, '+');
     }
     $summary = $hg->run('summary')->getOutput();
     $isDirty = 0 === count(array_filter($summary, function ($line) {
         return preg_match('/^commit: .*\\(clean\\)$/', $line) === 1;
     }));
     if ($isDirty) {
         $tag .= '-dirty';
     }
     return $tag;
 }