diff --git a/simvue/metadata.py b/simvue/metadata.py index 5d8540a0..197e03e1 100644 --- a/simvue/metadata.py +++ b/simvue/metadata.py @@ -30,41 +30,41 @@ def git_info(repository: str) -> dict[str, typing.Any]: """ try: git_repo = git.Repo(repository, search_parent_directories=True) - except git.InvalidGitRepositoryError: - return {} - current_commit: git.Commit = git_repo.head.commit - author_list: set[str] = set( - email - for commit in git_repo.iter_commits("--all") - if "noreply" not in (email := (commit.author.email or "")) - and "[bot]" not in (commit.author.name or "") - ) + except (git.InvalidGitRepositoryError, ValueError): + current_commit: git.Commit = git_repo.head.commit + author_list: set[str] = set( + email + for commit in git_repo.iter_commits("--all") + if "noreply" not in (email := (commit.author.email or "")) + and "[bot]" not in (commit.author.name or "") + ) - ref: str = current_commit.hexsha + ref: str = current_commit.hexsha - # In the case where the repository is dirty blame should point to the - # current developer, not the person responsible for the latest commit - if dirty := git_repo.is_dirty(): - blame = git_repo.config_reader().get_value("user", "email", "unknown") - else: - blame = current_commit.committer.email + # In the case where the repository is dirty blame should point to the + # current developer, not the person responsible for the latest commit + if dirty := git_repo.is_dirty(): + blame = git_repo.config_reader().get_value("user", "email", "unknown") + else: + blame = current_commit.committer.email - for tag in git_repo.tags: - if tag.commit == current_commit: - ref = tag.name - break + for tag in git_repo.tags: + if tag.commit == current_commit: + ref = tag.name + break - return { - "git.authors": json.dumps(list(author_list)), - "git.ref": ref, - "git.msg": current_commit.message.strip(), - "git.time_stamp": current_commit.committed_datetime.strftime( - "%Y-%m-%d %H:%M:%S %z UTC" - ), - "git.blame": blame, - "git.url": git_repo.remote().url, - "git.dirty": dirty, - } + return { + "git.authors": json.dumps(list(author_list)), + "git.ref": ref, + "git.msg": current_commit.message.strip(), + "git.time_stamp": current_commit.committed_datetime.strftime( + "%Y-%m-%d %H:%M:%S %z UTC" + ), + "git.blame": blame, + "git.url": git_repo.remote().url, + "git.dirty": dirty, + } + return {} if __name__ in "__main__":