mirror of
https://github.com/klaussilveira/gitlist.git
synced 2025-11-18 03:30:55 +01:00
Issue #61: Read default branch from .git/HEAD
This commit is contained in:
@@ -2,7 +2,8 @@
|
|||||||
|
|
||||||
$app->get('{repo}/', function($repo) use($app) {
|
$app->get('{repo}/', function($repo) use($app) {
|
||||||
$repository = $app['git']->getRepository($app['git.repos'] . $repo);
|
$repository = $app['git']->getRepository($app['git.repos'] . $repo);
|
||||||
$tree = $repository->getTree('master');
|
$defaultBranch = $repository->getHead();
|
||||||
|
$tree = $repository->getTree($defaultBranch);
|
||||||
$breadcrumbs = $app['utils']->getBreadcrumbs("$repo/");
|
$breadcrumbs = $app['utils']->getBreadcrumbs("$repo/");
|
||||||
|
|
||||||
return $app['twig']->render('tree.twig', array(
|
return $app['twig']->render('tree.twig', array(
|
||||||
@@ -10,7 +11,7 @@ $app->get('{repo}/', function($repo) use($app) {
|
|||||||
'page' => 'files',
|
'page' => 'files',
|
||||||
'files' => $tree->output(),
|
'files' => $tree->output(),
|
||||||
'repo' => $repo,
|
'repo' => $repo,
|
||||||
'branch' => 'master',
|
'branch' => $defaultBranch,
|
||||||
'path' => '',
|
'path' => '',
|
||||||
'parent' => '',
|
'parent' => '',
|
||||||
'breadcrumbs' => $breadcrumbs,
|
'breadcrumbs' => $breadcrumbs,
|
||||||
|
|||||||
@@ -406,6 +406,25 @@ class Repository
|
|||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the current HEAD.
|
||||||
|
*
|
||||||
|
* @return string the name of the HEAD branch.
|
||||||
|
*/
|
||||||
|
public function getHead()
|
||||||
|
{
|
||||||
|
$file = file_get_contents($this->getPath() . '/.git/HEAD');
|
||||||
|
foreach (explode("\n", $file) as $line) {
|
||||||
|
$m = array();
|
||||||
|
if (preg_match('#ref:\srefs/heads/(.+)#', $line, $m)) {
|
||||||
|
return $m[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Default to something sane if in a detached HEAD state.
|
||||||
|
return 'master';
|
||||||
|
}
|
||||||
|
|
||||||
public function getStatistics($branch)
|
public function getStatistics($branch)
|
||||||
{
|
{
|
||||||
// Calculate amount of files, extensions and file size
|
// Calculate amount of files, extensions and file size
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
{% for repository in repositories %}
|
{% for repository in repositories %}
|
||||||
<div class="repository">
|
<div class="repository">
|
||||||
<div class="repository-header">
|
<div class="repository-header">
|
||||||
<i class="icon-folder-open icon-spaced"></i> <a href="{{ baseurl }}/{{ repository.name }}/tree/master/">{{ repository.name }}</a>
|
<i class="icon-folder-open icon-spaced"></i> <a href="{{ baseurl }}/{{ repository.name }}">{{ repository.name }}</a>
|
||||||
<a href="{{ baseurl }}/{{ repository.name }}/master/rss/"><i class="rss pull-right"></i></a>
|
<a href="{{ baseurl }}/{{ repository.name }}/master/rss/"><i class="rss pull-right"></i></a>
|
||||||
</div>
|
</div>
|
||||||
<div class="repository-body">
|
<div class="repository-body">
|
||||||
|
|||||||
Reference in New Issue
Block a user