From f5db865a3ba074b1b7dd88236da930bf4e3c9279 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bor=20Gro=C5=A1elj=20Simi=C4=87?= Date: Sat, 23 Oct 2021 22:24:57 +0200 Subject: [PATCH] fix a 500 on refs/ in repos without a default branch --- gitsrht/blueprints/repo.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/gitsrht/blueprints/repo.py b/gitsrht/blueprints/repo.py index 61db55f..d615e5a 100644 --- a/gitsrht/blueprints/repo.py +++ b/gitsrht/blueprints/repo.py @@ -556,8 +556,12 @@ def refs(owner, repo): git_repo.get(git_repo.branches[branch].target) ) for branch in git_repo.raw_listall_branches(pygit2.GIT_BRANCH_LOCAL)] default_branch = git_repo.default_branch() + if default_branch: + _branch_key = lambda b: (b[1].raw_name == default_branch.raw_name, b[2].commit_time) + else: + _branch_key = lambda b: b[2].commit_time branches = sorted(branches, - key=lambda b: (b[1].raw_name == default_branch.raw_name, b[2].commit_time), + key=_branch_key, reverse=True) results_per_page = 10 -- 2.38.4