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

get_default_branch: Use HEAD instead of guessing #308

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
19 changes: 5 additions & 14 deletions klaus/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,20 +137,11 @@ def get_commit(self, rev):
raise KeyError(rev)

def get_default_branch(self):
"""Tries to guess the default repo branch name."""
for candidate in ["master", "main", "trunk", "default", "gh-pages"]:
try:
self.get_commit(candidate)
return candidate
except InaccessibleRef:
pass
for name in self.get_branch_names():
try:
self.get_commit(name)
return name
except InaccessibleRef:
pass
else:
"""Retrieves the default branch name from HEAD"""
try:
heads = [ head.split(b'/')[-1] for head in self.refs.follow(b'HEAD')[0] if head.startswith(b'refs/head') ]
return(heads[0].decode())
except InaccessibleRef:
return None

def get_ref_names_ordered_by_last_commit(self, prefix, exclude=None):
Expand Down