| 58 | |
| 59 | |
| 60 | class GitCommit(GitObject): |
| 61 | def __init__( |
| 62 | self, |
| 63 | rev: str, |
| 64 | title: str, |
| 65 | body: str = "", |
| 66 | author: str = "", |
| 67 | author_email: str = "", |
| 68 | parents: list[str] | None = None, |
| 69 | ) -> None: |
| 70 | self.rev = rev.strip() |
| 71 | self.title = title.strip() |
| 72 | self.body = body.strip() |
| 73 | self.author = author.strip() |
| 74 | self.author_email = author_email.strip() |
| 75 | self.parents = parents or [] |
| 76 | |
| 77 | @property |
| 78 | def message(self) -> str: |
| 79 | return f"{self.title}\n\n{self.body}".strip() |
| 80 | |
| 81 | @classmethod |
| 82 | def from_rev_and_commit(cls, rev_and_commit: str) -> GitCommit: |
| 83 | """Create a GitCommit instance from a formatted commit string. |
| 84 | |
| 85 | This method parses a multi-line string containing commit information in the following format: |
| 86 | ``` |
| 87 | <rev> |
| 88 | <parents> |
| 89 | <title> |
| 90 | <author> |
| 91 | <author_email> |
| 92 | <body_line_1> |
| 93 | <body_line_2> |
| 94 | ... |
| 95 | ``` |
| 96 | |
| 97 | Args: |
| 98 | rev_and_commit (str): A string containing commit information with fields separated by newlines. |
| 99 | - rev: The commit hash/revision |
| 100 | - parents: Space-separated list of parent commit hashes |
| 101 | - title: The commit title/message |
| 102 | - author: The commit author's name |
| 103 | - author_email: The commit author's email |
| 104 | - body: Optional multi-line commit body |
| 105 | |
| 106 | Returns: |
| 107 | GitCommit: A new GitCommit instance with the parsed information. |
| 108 | |
| 109 | Example: |
| 110 | >>> commit_str = '''abc123 |
| 111 | ... def456 ghi789 |
| 112 | ... feat: add new feature |
| 113 | ... John Doe |
| 114 | ... john@example.com |
| 115 | ... This is a detailed description |
| 116 | ... of the new feature''' |
| 117 | >>> commit = GitCommit.from_rev_and_commit(commit_str) |
nothing calls this directly
no outgoing calls
no test coverage detected