From 4774e65d0ff3f12dd596867936afff49c95988f9 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Wed, 19 Feb 2020 14:42:35 -0500 Subject: [PATCH] Fix IndexError on repos with no branches --- gitsrht/blueprints/repo.py | 5 ++++- gitsrht/git.py | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/gitsrht/blueprints/repo.py b/gitsrht/blueprints/repo.py index 73c2488..bf23fd1 100644 --- a/gitsrht/blueprints/repo.py +++ b/gitsrht/blueprints/repo.py @@ -147,7 +147,10 @@ def go_get(owner, repo, path): ]) def lookup_ref(git_repo, ref, path): - ref = ref or git_repo.default_branch().name[len("refs/heads/"):] + branch = git_repo.default_branch() + if not branch: + abort(404) + ref = ref or branch.name[len("refs/heads/"):] if not path: path = [] else: diff --git a/gitsrht/git.py b/gitsrht/git.py index 4831508..2a41fd3 100644 --- a/gitsrht/git.py +++ b/gitsrht/git.py @@ -55,6 +55,8 @@ class Repository(GitRepository): 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 -- 2.38.4