MCPcopy Create free account
hub / github.com/commitizen-tools/commitizen / from_rev_and_commit

Method from_rev_and_commit

commitizen/git.py:82–135  ·  view source on GitHub ↗

Create a GitCommit instance from a formatted commit string. This method parses a multi-line string containing commit information in the following format: ``` <body_l

(cls, rev_and_commit: str)

Source from the content-addressed store, hash-verified

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&#x27;s name
103 - author_email: The commit author&#x27;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 = ''&#x27;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''&#x27;
117 >>> commit = GitCommit.from_rev_and_commit(commit_str)
118 >>> commit.rev
119 'abc123'
120 >>> commit.title
121 'feat: add new feature'
122 >>> commit.parents
123 ['def456', 'ghi789']
124 """
125 rev, parents, title, author, author_email, *body_list = (
126 rev_and_commit.splitlines()
127 )
128 return cls(
129 rev=rev.strip(),
130 title=title.strip(),
131 body="\n".join(body_list).strip(),
132 author=author,
133 author_email=author_email,
134 parents=[p for p in parents.strip().split(" ") if p],
135 )
136
137 def __repr__(self) -> str:
138 return f"{self.title} ({self.rev})"

Callers 2

get_commitsFunction · 0.80

Calls

no outgoing calls

Tested by 1