@@ -30,41 +30,41 @@ def git_info(repository: str) -> dict[str, typing.Any]:
30
30
"""
31
31
try :
32
32
git_repo = git .Repo (repository , search_parent_directories = True )
33
- except git .InvalidGitRepositoryError :
34
- return {}
35
- current_commit : git .Commit = git_repo .head .commit
36
- author_list : set [str ] = set (
37
- email
38
- for commit in git_repo .iter_commits ("--all" )
39
- if "noreply" not in (email := (commit .author .email or "" ))
40
- and "[bot]" not in (commit .author .name or "" )
41
- )
33
+ except (git .InvalidGitRepositoryError , ValueError ):
34
+ current_commit : git .Commit = git_repo .head .commit
35
+ author_list : set [str ] = set (
36
+ email
37
+ for commit in git_repo .iter_commits ("--all" )
38
+ if "noreply" not in (email := (commit .author .email or "" ))
39
+ and "[bot]" not in (commit .author .name or "" )
40
+ )
42
41
43
- ref : str = current_commit .hexsha
42
+ ref : str = current_commit .hexsha
44
43
45
- # In the case where the repository is dirty blame should point to the
46
- # current developer, not the person responsible for the latest commit
47
- if dirty := git_repo .is_dirty ():
48
- blame = git_repo .config_reader ().get_value ("user" , "email" , "unknown" )
49
- else :
50
- blame = current_commit .committer .email
44
+ # In the case where the repository is dirty blame should point to the
45
+ # current developer, not the person responsible for the latest commit
46
+ if dirty := git_repo .is_dirty ():
47
+ blame = git_repo .config_reader ().get_value ("user" , "email" , "unknown" )
48
+ else :
49
+ blame = current_commit .committer .email
51
50
52
- for tag in git_repo .tags :
53
- if tag .commit == current_commit :
54
- ref = tag .name
55
- break
51
+ for tag in git_repo .tags :
52
+ if tag .commit == current_commit :
53
+ ref = tag .name
54
+ break
56
55
57
- return {
58
- "git.authors" : json .dumps (list (author_list )),
59
- "git.ref" : ref ,
60
- "git.msg" : current_commit .message .strip (),
61
- "git.time_stamp" : current_commit .committed_datetime .strftime (
62
- "%Y-%m-%d %H:%M:%S %z UTC"
63
- ),
64
- "git.blame" : blame ,
65
- "git.url" : git_repo .remote ().url ,
66
- "git.dirty" : dirty ,
67
- }
56
+ return {
57
+ "git.authors" : json .dumps (list (author_list )),
58
+ "git.ref" : ref ,
59
+ "git.msg" : current_commit .message .strip (),
60
+ "git.time_stamp" : current_commit .committed_datetime .strftime (
61
+ "%Y-%m-%d %H:%M:%S %z UTC"
62
+ ),
63
+ "git.blame" : blame ,
64
+ "git.url" : git_repo .remote ().url ,
65
+ "git.dirty" : dirty ,
66
+ }
67
+ return {}
68
68
69
69
70
70
if __name__ in "__main__" :
0 commit comments