better Head detection if refs/heads is pointing to non-existing master

This commit is contained in:
Peter Droogmans
2012-07-13 16:49:15 +02:00
parent dfc3c6eda8
commit 48a267d508

View File

@@ -422,14 +422,21 @@ class Repository
else {
return 'master';
}
// Find first existing branch
foreach (explode("\n", $file) as $line) {
$m = array();
if (preg_match('#ref:\srefs/heads/(.+)#', $line, $m)) {
return $m[1];
if ($this->hasBranch($m[1])) {
return $m[1];
}
}
}
// Default to something sane if in a detached HEAD state.
$branches = $this->getBranches();
if (!empty($branches)) {
return current($branches);
}
return 'master';
}