Skip to content

Expanded try except to handle half initialized git repos #389

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

Merged
merged 1 commit into from
Jun 7, 2024
Merged
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
62 changes: 31 additions & 31 deletions simvue/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__":
Expand Down
Loading