From e22daa33f4c194a9e6997188728fe1b7548a4434 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=BD=D0=B0=D0=B1?= Date: Thu, 30 Jul 2020 18:00:29 +0200 Subject: [PATCH] Make Repository.default_branch() simply read the default branch Alongside the previous commit this preserves the semantic of "default_branch() == None" being equivalent to "repository empty", but that is now managed by the post-update hook --- gitsrht/git.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/gitsrht/git.py b/gitsrht/git.py index 760a941..0d10918 100644 --- a/gitsrht/git.py +++ b/gitsrht/git.py @@ -52,13 +52,8 @@ class Repository(GitRepository): return super().get(ref) def default_branch(self): - branch = self.branches.get("master") - if not branch: - if not any(self.branches.local): - return None - branch = list(self.branches.local)[0] - branch = self.branches.get(branch) - return branch + head_ref = self.lookup_reference("HEAD") + return self.branches.get(head_ref.target[len("refs/heads/"):]) def default_branch_name(self): branch = self.default_branch() -- 2.38.4