Skip to content

Commit

Permalink
Repo page: if no default branch is found, use HEAD (#312)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonashaag authored Apr 8, 2023
1 parent aea4341 commit a542414
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
14 changes: 5 additions & 9 deletions klaus/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@ def _get_commit_time(ref_id):
if len(all_ids) > max_refs:
all_ids = sorted(all_ids)[:max_refs]
# Always add HEAD.
all_ids.append(self.dulwich_repo.refs[b"HEAD"])
try:
all_ids.append(self.dulwich_repo.refs[b"HEAD"])
except KeyError:
pass

commit_times = filter(None, map(_get_commit_time_cached, all_ids))
try:
Expand Down Expand Up @@ -179,14 +182,7 @@ def get_default_branch(self):
return candidate
except InaccessibleRef:
pass
for name in self.get_branch_names():
try:
self.get_commit(name)
return name
except InaccessibleRef:
pass
else:
return None
return None

@synchronized
def get_ref_names_ordered_by_last_commit(self, prefix, exclude=None):
Expand Down
6 changes: 5 additions & 1 deletion klaus/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,11 @@ def _get_repo_and_rev(repo, namespace=None, rev=None, path=None):
if rev is None:
rev = repo.get_default_branch()
if rev is None:
raise NotFound("Empty repository")
rev = "HEAD"
try:
repo.get_commit("HEAD")
except KeyError:
raise NotFound("No commits yet")

i = len(rev)
while i > 0:
Expand Down

0 comments on commit a542414

Please sign in to comment.