/** * Get the value of the element at the given dot key path. * * @param string $path Dot-notation key path. e.g. `parent.child` * @param null|mixed $default Default value to return * * @return mixed */ public function get($path, $default = null) { return Dot::get($this->data, $path, $default); }
/** * @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; }