Skip to content

Commit bfcf4aa

Browse files
committed
Add commit_or_none
1 parent 13c3cf8 commit bfcf4aa

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/git_autograder/helpers/commit_helper.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,12 @@ def __init__(self, repo: Repo) -> None:
1313
def commit(self, rev: Optional[Union[Commit_ish, str]]) -> GitAutograderCommit:
1414
c = self.repo.commit(rev)
1515
return GitAutograderCommit(c)
16+
17+
def commit_or_none(
18+
self, rev: Optional[Union[Commit_ish, str]]
19+
) -> Optional[GitAutograderCommit]:
20+
try:
21+
c = self.repo.commit(rev)
22+
return GitAutograderCommit(c)
23+
except Exception:
24+
return None

0 commit comments

Comments
 (0)