Skip to content

Commit

Permalink
πŸ‘Œ Add fallback if we cannot use git on the shell
Browse files Browse the repository at this point in the history
Under some circumstances, there may be no git or no shell access available. This gets the commit
date manually.
  • Loading branch information
micgro42 committed Jul 5, 2018
1 parent 067b4fb commit f519f9d
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions inc/infoutils.php
Expand Up @@ -76,6 +76,25 @@ function getVersionData(){

if ($date = shell_exec("git log -1 --pretty=format:'%cd' --date=short")) {
$version['date'] = hsc($date);
} else if (file_exists(DOKU_INC . '.git/HEAD')) {
// we cannot use git on the shell -- let's do it manually!
$headCommit = trim(file_get_contents(DOKU_INC . '.git/HEAD'));
if (strpos($headCommit, 'ref: ') === 0) {
// it is something like `ref: refs/heads/master`
$pathToHead = substr($headCommit, 5);
$headCommit = trim(file_get_contents(DOKU_INC . '.git/' . $pathToHead));
}
$subDir = substr($headCommit, 0, 2);
$fileName = substr($headCommit, 2);
$getCommitObject = DOKU_INC . ".git/objects/$subDir/$fileName";
$commit = zlib_decode(file_get_contents($getCommitObject));
$committerLine = explode("\n", $commit)[3];
$committerData = explode(' ', $committerLine);
end($committerData);
$ts = prev($committerData);
if ($ts && $date = date('Y-m-d', $ts)) {
$version['date'] = $date;
}
}
}else{
global $updateVersion;
Expand Down

0 comments on commit f519f9d

Please sign in to comment.