MCPcopy Index your code
hub / github.com/initialcommit-com/git-sim / CherryPick

Class CherryPick

src/git_sim/cherrypick.py:10–72  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8
9
10class CherryPick(GitSimBaseCommand):
11 def __init__(self, commit: str, edit: str):
12 super().__init__()
13 self.commit = commit
14 self.edit = edit
15
16 try:
17 git.repo.fun.rev_parse(self.repo, self.commit)
18 except git.exc.BadName:
19 print(
20 "git-sim error: '"
21 + self.commit
22 + "' is not a valid Git ref or identifier."
23 )
24 sys.exit(1)
25
26 if self.commit in [branch.name for branch in self.repo.heads]:
27 self.selected_branches.append(self.commit)
28
29 try:
30 self.selected_branches.append(self.repo.active_branch.name)
31 except TypeError:
32 pass
33
34 self.cmd += f"cherry-pick {self.commit}" + (
35 (' -e "' + self.edit + '"') if self.edit else ""
36 )
37
38 def construct(self):
39 if not settings.stdout and not settings.output_only_path and not settings.quiet:
40 print(f"{settings.INFO_STRING} {self.cmd}")
41
42 if self.repo.active_branch.name in self.repo.git.branch(
43 "--contains", self.commit
44 ):
45 print(
46 "git-sim error: Commit '"
47 + self.commit
48 + "' is already included in the history of active branch '"
49 + self.repo.active_branch.name
50 + "'."
51 )
52 sys.exit(1)
53
54 self.show_intro()
55 head_commit = self.get_commit()
56 self.parse_commits(head_commit)
57 cherry_picked_commit = self.get_commit(self.commit)
58 self.parse_commits(cherry_picked_commit, shift=4 * m.DOWN)
59 self.parse_all()
60 self.center_frame_on_commit(head_commit)
61 self.setup_and_draw_parent(
62 head_commit,
63 self.edit if self.edit else cherry_picked_commit.message,
64 )
65 self.draw_arrow_between_commits(cherry_picked_commit.hexsha, "abcdef")
66 self.recenter_frame()
67 self.scale_frame()

Callers 1

cherry_pickFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected