Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repo page: if no default branch is found, use HEAD #312

Merged
merged 3 commits into from
Apr 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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