Skip to content

Commit

Permalink
MDL-43355 testing: Return the hash when HEAD points to a hash
Browse files Browse the repository at this point in the history
  • Loading branch information
David Monllao committed Dec 12, 2013
1 parent c36a240 commit 244da9d
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions lib/testing/classes/util.php
Original file line number Diff line number Diff line change
Expand Up @@ -644,18 +644,23 @@ public static function get_git_hash() {
return null;
}

$ref = file_get_contents("$CFG->dirroot/.git/HEAD");
if ($ref === false) {
$headcontent = file_get_contents("$CFG->dirroot/.git/HEAD");
if ($headcontent === false) {
return null;
}

$ref = trim($ref);
$headcontent = trim($headcontent);

if (strpos($ref, 'ref: ') !== 0) {
// If it is pointing to a hash we return it directly.
if (strlen($headcontent) === 40) {
return $headcontent;
}

if (strpos($headcontent, 'ref: ') !== 0) {
return null;
}

$ref = substr($ref, 5);
$ref = substr($headcontent, 5);

if (!file_exists("$CFG->dirroot/.git/$ref")) {
return null;
Expand Down

0 comments on commit 244da9d

Please sign in to comment.