Skip to content

Commit 9039e0d

Browse files
Add dummy shells for init and config subcommands
Signed-off-by: Jacob Stopak <jacob@initialcommit.io>
1 parent fea4616 commit 9039e0d

File tree

6 files changed

+207
-28
lines changed

6 files changed

+207
-28
lines changed

src/git_sim/__main__.py

+2
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,9 @@ def main(
251251
app.command()(git_sim.commands.clean)
252252
app.command()(git_sim.commands.clone)
253253
app.command()(git_sim.commands.commit)
254+
app.command()(git_sim.commands.config)
254255
app.command()(git_sim.commands.fetch)
256+
app.command()(git_sim.commands.init)
255257
app.command()(git_sim.commands.log)
256258
app.command()(git_sim.commands.merge)
257259
app.command()(git_sim.commands.mv)

src/git_sim/commands.py

+19
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,18 @@ def commit(
117117
handle_animations(scene=scene)
118118

119119

120+
def config(
121+
settings: List[str] = typer.Argument(
122+
default=None,
123+
help="The names and values of one or more config settings to set",
124+
)
125+
):
126+
from git_sim.config import Config
127+
128+
scene = Config(settings=settings)
129+
handle_animations(scene=scene)
130+
131+
120132
def fetch(
121133
remote: str = typer.Argument(
122134
default=None,
@@ -133,6 +145,13 @@ def fetch(
133145
handle_animations(scene=scene)
134146

135147

148+
def init():
149+
from git_sim.init import Init
150+
151+
scene = Init()
152+
handle_animations(scene=scene)
153+
154+
136155
def log(
137156
ctx: typer.Context,
138157
n: int = typer.Option(

src/git_sim/commit.py

+17-8
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def construct(self):
7575
self.vsplit_frame()
7676
self.setup_and_draw_zones(
7777
first_column_name="Working directory",
78-
second_column_name="Staging area",
78+
second_column_name="Staged files",
7979
third_column_name="New commit",
8080
)
8181

@@ -96,10 +96,19 @@ def populate_zones(
9696
if "git-sim_media" not in x.a_path:
9797
firstColumnFileNames.add(x.a_path)
9898

99-
for y in self.repo.index.diff("HEAD"):
100-
if "git-sim_media" not in y.a_path:
101-
secondColumnFileNames.add(y.a_path)
102-
thirdColumnFileNames.add(y.a_path)
103-
secondColumnArrowMap[y.a_path] = m.Arrow(
104-
stroke_width=3, color=self.fontColor
105-
)
99+
if self.head_exists():
100+
for y in self.repo.index.diff("HEAD"):
101+
if "git-sim_media" not in y.a_path:
102+
secondColumnFileNames.add(y.a_path)
103+
thirdColumnFileNames.add(y.a_path)
104+
secondColumnArrowMap[y.a_path] = m.Arrow(
105+
stroke_width=3, color=self.fontColor
106+
)
107+
else:
108+
for y in self.repo.index.diff(None, staged=True):
109+
if "git-sim_media" not in y.a_path:
110+
secondColumnFileNames.add(y.a_path)
111+
thirdColumnFileNames.add(y.a_path)
112+
secondColumnArrowMap[y.a_path] = m.Arrow(
113+
stroke_width=3, color=self.fontColor
114+
)

src/git_sim/config.py

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import sys
2+
import os
3+
import git
4+
import numpy
5+
import tempfile
6+
import shutil
7+
import stat
8+
import re
9+
10+
import manim as m
11+
12+
from typing import List
13+
from argparse import Namespace
14+
15+
from git.exc import GitCommandError, InvalidGitRepositoryError
16+
from git.repo import Repo
17+
18+
from git_sim.git_sim_base_command import GitSimBaseCommand
19+
from git_sim.settings import settings
20+
21+
22+
class Config(GitSimBaseCommand):
23+
def __init__(self, settings: List[str]):
24+
super().__init__()
25+
self.settings = settings
26+
27+
for i, setting in enumerate(self.settings):
28+
if " " in setting:
29+
self.settings[i] = f"\"{setting}\""
30+
31+
self.cmd += f"{type(self).__name__.lower()} {' '.join(self.settings)}"
32+
33+
def construct(self):
34+
if not settings.stdout and not settings.output_only_path and not settings.quiet:
35+
print(f"{settings.INFO_STRING} {self.cmd}")
36+
37+
self.show_intro()
38+
#self.recenter_frame()
39+
#self.scale_frame()
40+
#self.add_details(repo_name)
41+
self.show_command_as_title()
42+
self.fadeout()
43+
self.show_outro()
44+
45+
def add_details(self, repo_name):
46+
text1 = m.Text(
47+
f"Successfully cloned from {self.url} into ./{repo_name}",
48+
font=self.font,
49+
font_size=20,
50+
color=self.fontColor,
51+
weight=m.BOLD,
52+
)
53+
text1.move_to([self.camera.frame.get_center()[0], 4, 0])
54+
55+
text2 = m.Text(
56+
f"Cloned repo log:",
57+
font=self.font,
58+
font_size=20,
59+
color=self.fontColor,
60+
weight=m.BOLD,
61+
)
62+
text2.move_to(text1.get_center()).shift(m.DOWN / 2)
63+
64+
self.toFadeOut.add(text1)
65+
self.toFadeOut.add(text2)
66+
self.recenter_frame()
67+
self.scale_frame()
68+
69+
if settings.animate:
70+
self.play(m.AddTextLetterByLetter(text1), m.AddTextLetterByLetter(text2))
71+
else:
72+
self.add(text1, text2)

src/git_sim/git_sim_base_command.py

+33-20
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,9 @@ def construct(self):
101101
self.show_outro()
102102

103103
def get_commit(self, sha_or_ref="HEAD"):
104-
return self.repo.commit(sha_or_ref)
104+
if self.head_exists():
105+
return self.repo.commit(sha_or_ref)
106+
return "dark"
105107

106108
def get_default_commits(self):
107109
defaultCommits = [self.get_commit()]
@@ -646,7 +648,9 @@ def setup_and_draw_zones(
646648
reverse=False,
647649
):
648650
if self.check_all_dark():
649-
self.zone_title_offset = 2.0 if platform.system() == "Windows" else 6.0
651+
self.zone_title_offset = 2.0 if platform.system() == "Windows" else 2.0
652+
elif len(self.drawnCommits) == 1:
653+
self.zone_title_offset = 2.0 if platform.system() == "Windows" else 2.0
650654

651655
horizontal = m.Line(
652656
(
@@ -928,6 +932,9 @@ def populate_zones(
928932
firstColumnFileNames.add(z)
929933

930934
def center_frame_on_commit(self, commit):
935+
if not commit or commit == "dark":
936+
return
937+
931938
if settings.animate:
932939
self.play(
933940
self.camera.frame.animate.move_to(
@@ -938,6 +945,9 @@ def center_frame_on_commit(self, commit):
938945
self.camera.frame.move_to(self.drawnCommits[commit.hexsha].get_center())
939946

940947
def reset_head_branch(self, hexsha, shift=numpy.array([0.0, 0.0, 0.0])):
948+
if not self.head_exists():
949+
return
950+
941951
if settings.animate:
942952
self.play(
943953
self.drawnRefs["HEAD"].animate.move_to(
@@ -1046,25 +1056,28 @@ def setup_and_draw_parent(
10461056
fill_opacity=self.ref_fill_opacity,
10471057
)
10481058
circle.height = 1
1049-
circle.next_to(
1050-
self.drawnCommits[child.hexsha],
1051-
m.LEFT if settings.reverse else m.RIGHT,
1052-
buff=1.5,
1053-
)
1059+
if child != "dark":
1060+
circle.next_to(
1061+
self.drawnCommits[child.hexsha],
1062+
m.LEFT if settings.reverse else m.RIGHT,
1063+
buff=1.5,
1064+
)
1065+
10541066
circle.shift(shift)
10551067

1056-
start = circle.get_center()
1057-
end = self.drawnCommits[child.hexsha].get_center()
1058-
arrow = m.Arrow(
1059-
start,
1060-
end,
1061-
color=self.fontColor,
1062-
stroke_width=self.arrow_stroke_width,
1063-
tip_shape=self.arrow_tip_shape,
1064-
max_stroke_width_to_length_ratio=1000,
1065-
)
1066-
length = numpy.linalg.norm(start - end) - (1.5 if start[1] == end[1] else 3)
1067-
arrow.set_length(length)
1068+
if child != "dark":
1069+
start = circle.get_center()
1070+
end = self.drawnCommits[child.hexsha].get_center()
1071+
arrow = m.Arrow(
1072+
start,
1073+
end,
1074+
color=self.fontColor,
1075+
stroke_width=self.arrow_stroke_width,
1076+
tip_shape=self.arrow_tip_shape,
1077+
max_stroke_width_to_length_ratio=1000,
1078+
)
1079+
length = numpy.linalg.norm(start - end) - (1.5 if start[1] == end[1] else 3)
1080+
arrow.set_length(length)
10681081

10691082
commitId = m.Text(
10701083
"abcdef",
@@ -1102,7 +1115,7 @@ def setup_and_draw_parent(
11021115
self.drawnCommits["abcdef"] = circle
11031116
self.toFadeOut.add(circle)
11041117

1105-
if draw_arrow:
1118+
if draw_arrow and child != "dark":
11061119
if settings.animate:
11071120
self.play(m.Create(arrow), run_time=1 / settings.speed)
11081121
else:

src/git_sim/init.py

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import sys
2+
import os
3+
from argparse import Namespace
4+
5+
import git
6+
import manim as m
7+
import numpy
8+
import tempfile
9+
import shutil
10+
import stat
11+
import re
12+
13+
from git.exc import GitCommandError, InvalidGitRepositoryError
14+
from git.repo import Repo
15+
16+
from git_sim.git_sim_base_command import GitSimBaseCommand
17+
from git_sim.settings import settings
18+
19+
20+
class Init(GitSimBaseCommand):
21+
def __init__(self):
22+
super().__init__()
23+
self.cmd += f"{type(self).__name__.lower()}"
24+
25+
def construct(self):
26+
if not settings.stdout and not settings.output_only_path and not settings.quiet:
27+
print(f"{settings.INFO_STRING} {self.cmd}")
28+
29+
self.show_intro()
30+
#self.recenter_frame()
31+
#self.scale_frame()
32+
#self.add_details(repo_name)
33+
self.show_command_as_title()
34+
self.fadeout()
35+
self.show_outro()
36+
37+
def add_details(self, repo_name):
38+
text1 = m.Text(
39+
f"Successfully cloned from {self.url} into ./{repo_name}",
40+
font=self.font,
41+
font_size=20,
42+
color=self.fontColor,
43+
weight=m.BOLD,
44+
)
45+
text1.move_to([self.camera.frame.get_center()[0], 4, 0])
46+
47+
text2 = m.Text(
48+
f"Cloned repo log:",
49+
font=self.font,
50+
font_size=20,
51+
color=self.fontColor,
52+
weight=m.BOLD,
53+
)
54+
text2.move_to(text1.get_center()).shift(m.DOWN / 2)
55+
56+
self.toFadeOut.add(text1)
57+
self.toFadeOut.add(text2)
58+
self.recenter_frame()
59+
self.scale_frame()
60+
61+
if settings.animate:
62+
self.play(m.AddTextLetterByLetter(text1), m.AddTextLetterByLetter(text2))
63+
else:
64+
self.add(text1, text2)

0 commit comments

Comments
 (0)