Skip to content

Commit 8cbb5f9

Browse files
Add clean subcommand
Signed-off-by: Jacob Stopak <jacob@initialcommit.io>
1 parent 0df3927 commit 8cbb5f9

File tree

3 files changed

+135
-0
lines changed

3 files changed

+135
-0
lines changed

Diff for: git_sim/__main__.py

+1
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ def main(
200200
app.command()(git_sim.commands.branch)
201201
app.command()(git_sim.commands.checkout)
202202
app.command()(git_sim.commands.cherry_pick)
203+
app.command()(git_sim.commands.clean)
203204
app.command()(git_sim.commands.clone)
204205
app.command()(git_sim.commands.commit)
205206
app.command()(git_sim.commands.fetch)

Diff for: git_sim/clean.py

+126
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
import sys
2+
import git
3+
import manim as m
4+
5+
from typing import List
6+
7+
from git_sim.git_sim_base_command import GitSimBaseCommand
8+
from git_sim.settings import settings
9+
10+
11+
class Clean(GitSimBaseCommand):
12+
def __init__(self):
13+
super().__init__()
14+
self.hide_first_tag = True
15+
self.allow_no_commits = True
16+
settings.hide_merged_branches = True
17+
self.n = self.n_default
18+
19+
try:
20+
self.selected_branches.append(self.repo.active_branch.name)
21+
except TypeError:
22+
pass
23+
24+
def construct(self):
25+
if not settings.stdout and not settings.output_only_path and not settings.quiet:
26+
print(
27+
f"{settings.INFO_STRING} {type(self).__name__.lower()}"
28+
)
29+
30+
self.show_intro()
31+
self.parse_commits()
32+
self.recenter_frame()
33+
self.scale_frame()
34+
self.vsplit_frame()
35+
self.setup_and_draw_zones(
36+
first_column_name="Untracked files",
37+
second_column_name="----",
38+
third_column_name="Deleted files",
39+
)
40+
self.fadeout()
41+
self.show_outro()
42+
43+
def create_zone_text(
44+
self,
45+
firstColumnFileNames,
46+
secondColumnFileNames,
47+
thirdColumnFileNames,
48+
firstColumnFiles,
49+
secondColumnFiles,
50+
thirdColumnFiles,
51+
firstColumnFilesDict,
52+
secondColumnFilesDict,
53+
thirdColumnFilesDict,
54+
firstColumnTitle,
55+
secondColumnTitle,
56+
thirdColumnTitle,
57+
horizontal2,
58+
):
59+
for i, f in enumerate(firstColumnFileNames):
60+
text = (
61+
m.Text(
62+
self.trim_path(f),
63+
font="Monospace",
64+
font_size=24,
65+
color=self.fontColor,
66+
)
67+
.move_to(
68+
(firstColumnTitle.get_center()[0], horizontal2.get_center()[1], 0)
69+
)
70+
.shift(m.DOWN * 0.5 * (i + 1))
71+
)
72+
firstColumnFiles.add(text)
73+
firstColumnFilesDict[f] = text
74+
75+
for j, f in enumerate(secondColumnFileNames):
76+
text = (
77+
m.Text(
78+
self.trim_path(f),
79+
font="Monospace",
80+
font_size=24,
81+
color=self.fontColor,
82+
)
83+
.move_to(
84+
(secondColumnTitle.get_center()[0], horizontal2.get_center()[1], 0)
85+
)
86+
.shift(m.DOWN * 0.5 * (j + 1))
87+
)
88+
secondColumnFiles.add(text)
89+
secondColumnFilesDict[f] = text
90+
91+
for h, f in enumerate(thirdColumnFileNames):
92+
text = (
93+
m.MarkupText(
94+
"<span strikethrough='true' strikethrough_color='"
95+
+ self.fontColor
96+
+ "'>"
97+
+ self.trim_path(f)
98+
+ "</span>",
99+
font="Monospace",
100+
font_size=24,
101+
color=self.fontColor,
102+
)
103+
.move_to(
104+
(thirdColumnTitle.get_center()[0], horizontal2.get_center()[1], 0)
105+
)
106+
.shift(m.DOWN * 0.5 * (h + 1))
107+
)
108+
thirdColumnFiles.add(text)
109+
thirdColumnFilesDict[f] = text
110+
111+
def populate_zones(
112+
self,
113+
firstColumnFileNames,
114+
secondColumnFileNames,
115+
thirdColumnFileNames,
116+
firstColumnArrowMap={},
117+
secondColumnArrowMap={},
118+
thirdColumnArrowMap={},
119+
):
120+
for z in self.repo.untracked_files:
121+
if "git-sim_media" not in z:
122+
firstColumnFileNames.add(z)
123+
thirdColumnFileNames.add(z)
124+
firstColumnArrowMap[z] = m.Arrow(
125+
stroke_width=3, color=self.fontColor
126+
)

Diff for: git_sim/commands.py

+8
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,14 @@ def cherry_pick(
7777
handle_animations(scene=scene)
7878

7979

80+
def clean():
81+
from git_sim.clean import Clean
82+
83+
settings.hide_first_tag = True
84+
scene = Clean()
85+
handle_animations(scene=scene)
86+
87+
8088
def clone(
8189
url: str = typer.Argument(
8290
...,

0 commit comments

Comments
 (0)