-
-
Notifications
You must be signed in to change notification settings - Fork 115
/
Copy pathrestore.py
79 lines (68 loc) · 2.7 KB
/
restore.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import sys
import manim as m
from typing import List
from git_sim.git_sim_base_command import GitSimBaseCommand
from git_sim.settings import settings
class Restore(GitSimBaseCommand):
def __init__(self, files: List[str], staged: bool):
super().__init__()
self.files = files
self.staged = staged
settings.hide_merged_branches = True
self.n = self.n_default
try:
self.selected_branches.append(self.repo.active_branch.name)
except TypeError:
pass
if not self.staged:
for file in self.files:
if file not in [x.a_path for x in self.repo.index.diff(None)]:
print(f"git-sim error: No modified file with name: '{file}'")
sys.exit()
else:
for file in self.files:
if file not in [y.a_path for y in self.repo.index.diff("HEAD")]:
print(
f"git-sim error: No modified or staged file with name: '{file}'"
)
sys.exit()
self.cmd += f"{type(self).__name__.lower()}{' --staged' if self.staged else ''} {' '.join(self.files)}"
def construct(self):
if not settings.stdout and not settings.output_only_path and not settings.quiet:
print(f"{settings.INFO_STRING} {self.cmd}")
self.show_intro()
self.parse_commits()
self.recenter_frame()
self.scale_frame()
self.vsplit_frame()
self.setup_and_draw_zones(reverse=True)
self.show_command_as_title()
self.fadeout()
self.show_outro()
def populate_zones(
self,
firstColumnFileNames,
secondColumnFileNames,
thirdColumnFileNames,
firstColumnArrowMap={},
secondColumnArrowMap={},
thirdColumnArrowMap={},
):
for x in self.repo.index.diff(None):
if "git-sim_media" not in x.a_path:
secondColumnFileNames.add(x.a_path)
for file in self.files:
if file == x.a_path:
thirdColumnFileNames.add(x.a_path)
secondColumnArrowMap[x.a_path] = m.Arrow(
stroke_width=3, color=self.fontColor
)
for y in self.repo.index.diff("HEAD"):
if "git-sim_media" not in y.a_path:
firstColumnFileNames.add(y.a_path)
for file in self.files:
if file == y.a_path:
secondColumnFileNames.add(y.a_path)
firstColumnArrowMap[y.a_path] = m.Arrow(
stroke_width=3, color=self.fontColor
)