From 244da9d1f8e30c3c224d38d9322b06e3cd47b6a0 Mon Sep 17 00:00:00 2001 From: David Monllao Date: Thu, 12 Dec 2013 17:26:22 +0800 Subject: [PATCH] MDL-43355 testing: Return the hash when HEAD points to a hash --- lib/testing/classes/util.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/testing/classes/util.php b/lib/testing/classes/util.php index 41a4243318a5c..661481fd68ad4 100644 --- a/lib/testing/classes/util.php +++ b/lib/testing/classes/util.php @@ -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;