MCPcopy Create free account
hub / github.com/ElementsProject/elements / check_commit

Function check_commit

contrib/review-prs.py:190–218  ·  view source on GitHub ↗

Verify some invariants about a commit, and fill in the full parent commid IDs.

(commit, last_reviewed, incoming_commit)

Source from the content-addressed store, hash-verified

188 return merged_commits
189
190def check_commit(commit, last_reviewed, incoming_commit) -> None:
191 """Verify some invariants about a commit, and fill in the full parent commid IDs."""
192
193 cid = commit["cid"]
194 parents = shell(f"git cat-file -p {cid} | grep '^parent'")
195 if len(parents) != 2:
196 print(f"WARNING: Expected merge, but commit {cid} has {parents} parents, which is not two! Please hand-review.")
197 return
198
199 parent_cids = []
200 for p in parents:
201 m = re.fullmatch("parent ([0-9a-f]+)", p)
202 assert m is not None
203 parent_cids.append(m.group(1))
204
205 full_merged_cid = shell_oneline(f"git rev-parse {commit['merged_cid']}")
206 if parent_cids[1] != full_merged_cid:
207 raise Exception("Merge isn't merging what the commit message claims to be merging")
208
209 if parent_cids[0] != last_reviewed:
210 raise Exception("First parent of next commit to review should be last commit reviewed.")
211
212 if full_merged_cid != incoming_commit["cid"]:
213 print("WARNING: Merge isn't merging the next expected Bitcoin/Elements commit.")
214 print("This could mean something was skipped, or it could just mean that some extra fixup commits were added.")
215 print("If the diff looks really wrong, stop here -- some manual review will be required.")
216
217 commit["parent_cid"] = parent_cids[0]
218 commit["merged_cid"] = full_merged_cid
219
220def check_or_create_worktree(path) -> None:
221 """Verify that a git worktree (or repo) exists at `path`. Offer to create it if missing. Exit if something is wrong."""

Callers 1

mainFunction · 0.85

Calls 3

shellFunction · 0.85
shell_onelineFunction · 0.85
ExceptionClass · 0.85

Tested by

no test coverage detected