Skip to content

Commit

Permalink
Merge pull request Ericsson#3647 from csordasmarton/fix_blame_info_ex…
Browse files Browse the repository at this point in the history
…ceptions

[web] Fix exceptions during blame information storage
  • Loading branch information
bruntib authored Apr 8, 2022
2 parents cbfc9ac + 21e93e0 commit ed490ba
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions web/client/codechecker_client/blame_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,41 @@
FileBlameInfo = Dict[str, Optional[Dict]]


def __get_tracking_branch(repo: Repo) -> Optional[str]:
"""
Get the tracking branch name or the current commit hash from the given
repository.
"""
try:
# If a commit is checked out, accessing the active_branch member will
# throw an error.
return str(repo.active_branch.tracking_branch())
except Exception:
pass

try:
# Use the current commit hash if it's available.
return repo.head.commit.hexsha
except Exception:
pass

return None


def __get_blame_info(file_path: str):
""" Get blame info for the given file. """
try:
repo = Repo(file_path, search_parent_directories=True)
except InvalidGitRepositoryError:
return

tracking_branch = None
try:
# If a commit is checked out, accessing the active_branch member will
# throw a type error. In this case we will use the current commit hash.
tracking_branch = str(repo.active_branch.tracking_branch())
except TypeError:
tracking_branch = repo.head.commit.hexsha
tracking_branch = __get_tracking_branch(repo)

remote_url = None
try:
# Handle the use case when a repository doesn't have a remote url.
remote_url = next(repo.remote().urls, None)
except ValueError:
except Exception:
pass

try:
Expand Down

0 comments on commit ed490ba

Please sign in to comment.