Skip to content

Commit 0df3927

Browse files
Add mv subcommand
Signed-off-by: Jacob Stopak <jacob@initialcommit.io>
1 parent 4818b8d commit 0df3927

File tree

4 files changed

+112
-0
lines changed

4 files changed

+112
-0
lines changed

git_sim/__main__.py

+1
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ def main(
205205
app.command()(git_sim.commands.fetch)
206206
app.command()(git_sim.commands.log)
207207
app.command()(git_sim.commands.merge)
208+
app.command()(git_sim.commands.mv)
208209
app.command()(git_sim.commands.pull)
209210
app.command()(git_sim.commands.push)
210211
app.command()(git_sim.commands.rebase)

git_sim/commands.py

+17
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,23 @@ def merge(
166166
handle_animations(scene=scene)
167167

168168

169+
def mv(
170+
file: str = typer.Argument(
171+
default=None,
172+
help="The name of the file to change the name/path of",
173+
),
174+
new_file: str = typer.Argument(
175+
default=None,
176+
help="The new name/path of the file",
177+
),
178+
):
179+
from git_sim.mv import Mv
180+
181+
settings.hide_first_tag = True
182+
scene = Mv(file=file, new_file=new_file)
183+
handle_animations(scene=scene)
184+
185+
169186
def pull(
170187
remote: str = typer.Argument(
171188
default=None,

git_sim/git_sim_base_command.py

+4
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,10 @@ def setup_and_draw_zones(
842842

843843
self.toFadeOut.add(firstColumnFiles, secondColumnFiles, thirdColumnFiles)
844844

845+
self.firstColumnFiles = firstColumnFiles
846+
self.secondColumnFiles = secondColumnFiles
847+
self.thirdColumnFiles = thirdColumnFiles
848+
845849
def populate_zones(
846850
self,
847851
firstColumnFileNames,

git_sim/mv.py

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
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 Mv(GitSimBaseCommand):
12+
def __init__(self, file: str, new_file: str):
13+
super().__init__()
14+
self.hide_first_tag = True
15+
self.allow_no_commits = True
16+
self.file = file
17+
self.new_file = new_file
18+
settings.hide_merged_branches = True
19+
self.n = self.n_default
20+
21+
try:
22+
self.selected_branches.append(self.repo.active_branch.name)
23+
except TypeError:
24+
pass
25+
26+
try:
27+
self.repo.git.ls_files("--error-unmatch", self.file)
28+
except:
29+
print(f"git-sim error: No tracked file with name: '{file}'")
30+
sys.exit()
31+
32+
def construct(self):
33+
if not settings.stdout and not settings.output_only_path and not settings.quiet:
34+
print(
35+
f"{settings.INFO_STRING} {type(self).__name__.lower()} {self.file} {self.new_file}"
36+
)
37+
38+
self.show_intro()
39+
self.parse_commits()
40+
self.recenter_frame()
41+
self.scale_frame()
42+
self.vsplit_frame()
43+
self.setup_and_draw_zones(
44+
first_column_name="Working directory",
45+
second_column_name="Staging area",
46+
third_column_name="Renamed files",
47+
)
48+
self.rename_moved_file()
49+
self.fadeout()
50+
self.show_outro()
51+
52+
def populate_zones(
53+
self,
54+
firstColumnFileNames,
55+
secondColumnFileNames,
56+
thirdColumnFileNames,
57+
firstColumnArrowMap={},
58+
secondColumnArrowMap={},
59+
thirdColumnArrowMap={},
60+
):
61+
if self.file in [x.a_path for x in self.repo.index.diff("HEAD")]:
62+
secondColumnFileNames.add(self.file)
63+
secondColumnArrowMap[self.file] = m.Arrow(
64+
stroke_width=3, color=self.fontColor
65+
)
66+
else:
67+
firstColumnFileNames.add(self.file)
68+
firstColumnArrowMap[self.file] = m.Arrow(
69+
stroke_width=3, color=self.fontColor
70+
)
71+
72+
thirdColumnFileNames.add(self.file)
73+
74+
def rename_moved_file(self):
75+
for file in self.thirdColumnFiles:
76+
new_file = m.Text(
77+
self.trim_path(self.new_file),
78+
font="Monospace",
79+
font_size=24,
80+
color=self.fontColor,
81+
)
82+
new_file.move_to(file.get_center())
83+
if settings.animate:
84+
self.play(m.FadeOut(file), run_time=1 / settings.speed)
85+
self.toFadeOut.remove(file)
86+
self.play(m.AddTextLetterByLetter(new_file))
87+
self.toFadeOut.add(new_file)
88+
else:
89+
self.remove(file)
90+
self.add(new_file)

0 commit comments

Comments
 (0)