M gitsrht/git.py => gitsrht/git.py +7 -0
@@ 60,6 60,13 @@ class Repository(GitRepository):
branch = self.branches.get(branch)
return branch
+ def default_branch_name(self):
+ branch = self.default_branch()
+ if branch:
+ return branch.name[len("refs/heads/"):]
+ else:
+ return None
+
@property
def is_empty(self):
return len(list(self.branches.local)) == 0
M gitsrht/templates/utils.html => gitsrht/templates/utils.html +1 -2
@@ 1,6 1,5 @@
{% macro breadcrumb(ref, repo, path, path_join) %}
-{# TODO: Default branches other than master #}
-{% if ref != "master" %}
+{% if ref != repo.git_repo.default_branch_name() %}
<span style="margin-right: 1rem">
<span class="text-muted">ref:</span> {{ ref }}
</span>
M gitsrht/types/__init__.py => gitsrht/types/__init__.py +9 -0
@@ 3,6 3,7 @@ import sqlalchemy as sa
from sqlalchemy import event
from srht.database import Base
from srht.oauth import ExternalUserMixin, ExternalOAuthTokenMixin
+from gitsrht.git import Repository as GitRepository
from scmsrht.repos import BaseAccessMixin, BaseRedirectMixin
from scmsrht.repos import BaseRepositoryMixin, RepoVisibility
@@ 19,6 20,8 @@ class Redirect(Base, BaseRedirectMixin):
pass
class Repository(Base, BaseRepositoryMixin):
+ _git_repo = None
+
def update_visibility(self):
if not os.path.exists(self.path):
# Repo dir not initialized yet
@@ 34,6 37,12 @@ class Repository(Base, BaseRepositoryMixin):
elif not should_exist and os.path.exists(path):
os.unlink(path)
+ @property
+ def git_repo(self):
+ if not self._git_repo:
+ self._git_repo = GitRepository(self.path)
+ return self._git_repo
+
def update_visibility_event(mapper, connection, target):
target.update_visibility()