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

Class Merge

src/git_sim/merge.py:15–202  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

13
14
15class Merge(GitSimBaseCommand):
16 def __init__(self, branch: str, no_ff: bool, message: str):
17 super().__init__()
18 self.branch = branch
19 self.no_ff = no_ff
20 self.message = message
21
22 try:
23 git.repo.fun.rev_parse(self.repo, self.branch)
24 except git.exc.BadName:
25 print(
26 "git-sim error: '"
27 + self.branch
28 + "' is not a valid Git ref or identifier."
29 )
30 sys.exit(1)
31
32 self.ff = False
33 if self.branch in [branch.name for branch in self.repo.heads]:
34 self.selected_branches.append(self.branch)
35
36 try:
37 self.selected_branches.append(self.repo.active_branch.name)
38 except TypeError:
39 pass
40
41 self.cmd += f"{type(self).__name__.lower()} {self.branch} {'--no-ff' if self.no_ff else ''}"
42
43 def construct(self):
44 if not settings.stdout and not settings.output_only_path and not settings.quiet:
45 print(f"{settings.INFO_STRING} {self.cmd}")
46
47 if self.repo.active_branch.name in self.repo.git.branch(
48 "--contains", self.branch
49 ):
50 print(
51 "git-sim error: Branch '"
52 + self.branch
53 + "' is already included in the history of active branch '"
54 + self.repo.active_branch.name
55 + "'."
56 )
57 sys.exit(1)
58
59 self.show_intro()
60 head_commit = self.get_commit()
61 branch_commit = self.get_commit(self.branch)
62
63 if self.branch not in self.get_remote_tracking_branches():
64 if self.branch in self.repo.git.branch("--contains", head_commit.hexsha):
65 self.ff = True
66 else:
67 if self.branch in self.repo.git.branch(
68 "-r", "--contains", head_commit.hexsha
69 ):
70 self.ff = True
71
72 if self.ff:

Callers 1

mergeFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected