|
| 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 Rm(GitSimBaseCommand): |
| 12 | + def __init__(self, files: List[str]): |
| 13 | + super().__init__() |
| 14 | + self.hide_first_tag = True |
| 15 | + self.allow_no_commits = True |
| 16 | + self.files = files |
| 17 | + settings.hide_merged_branches = True |
| 18 | + self.n = self.n_default |
| 19 | + |
| 20 | + try: |
| 21 | + self.selected_branches.append(self.repo.active_branch.name) |
| 22 | + except TypeError: |
| 23 | + pass |
| 24 | + |
| 25 | + for file in self.files: |
| 26 | + try: |
| 27 | + self.repo.git.ls_files("--error-unmatch", 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()} {' '.join(self.files)}" |
| 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="Removed files", |
| 47 | + ) |
| 48 | + self.fadeout() |
| 49 | + self.show_outro() |
| 50 | + |
| 51 | + def create_zone_text( |
| 52 | + self, |
| 53 | + firstColumnFileNames, |
| 54 | + secondColumnFileNames, |
| 55 | + thirdColumnFileNames, |
| 56 | + firstColumnFiles, |
| 57 | + secondColumnFiles, |
| 58 | + thirdColumnFiles, |
| 59 | + firstColumnFilesDict, |
| 60 | + secondColumnFilesDict, |
| 61 | + thirdColumnFilesDict, |
| 62 | + firstColumnTitle, |
| 63 | + secondColumnTitle, |
| 64 | + thirdColumnTitle, |
| 65 | + horizontal2, |
| 66 | + ): |
| 67 | + for i, f in enumerate(firstColumnFileNames): |
| 68 | + text = ( |
| 69 | + m.Text( |
| 70 | + self.trim_path(f), |
| 71 | + font="Monospace", |
| 72 | + font_size=24, |
| 73 | + color=self.fontColor, |
| 74 | + ) |
| 75 | + .move_to( |
| 76 | + (firstColumnTitle.get_center()[0], horizontal2.get_center()[1], 0) |
| 77 | + ) |
| 78 | + .shift(m.DOWN * 0.5 * (i + 1)) |
| 79 | + ) |
| 80 | + firstColumnFiles.add(text) |
| 81 | + firstColumnFilesDict[f] = text |
| 82 | + |
| 83 | + for j, f in enumerate(secondColumnFileNames): |
| 84 | + text = ( |
| 85 | + m.Text( |
| 86 | + self.trim_path(f), |
| 87 | + font="Monospace", |
| 88 | + font_size=24, |
| 89 | + color=self.fontColor, |
| 90 | + ) |
| 91 | + .move_to( |
| 92 | + (secondColumnTitle.get_center()[0], horizontal2.get_center()[1], 0) |
| 93 | + ) |
| 94 | + .shift(m.DOWN * 0.5 * (j + 1)) |
| 95 | + ) |
| 96 | + secondColumnFiles.add(text) |
| 97 | + secondColumnFilesDict[f] = text |
| 98 | + |
| 99 | + for h, f in enumerate(thirdColumnFileNames): |
| 100 | + text = ( |
| 101 | + m.MarkupText( |
| 102 | + "<span strikethrough='true' strikethrough_color='" |
| 103 | + + self.fontColor |
| 104 | + + "'>" |
| 105 | + + self.trim_path(f) |
| 106 | + + "</span>", |
| 107 | + font="Monospace", |
| 108 | + font_size=24, |
| 109 | + color=self.fontColor, |
| 110 | + ) |
| 111 | + .move_to( |
| 112 | + (thirdColumnTitle.get_center()[0], horizontal2.get_center()[1], 0) |
| 113 | + ) |
| 114 | + .shift(m.DOWN * 0.5 * (h + 1)) |
| 115 | + ) |
| 116 | + thirdColumnFiles.add(text) |
| 117 | + thirdColumnFilesDict[f] = text |
| 118 | + |
| 119 | + def populate_zones( |
| 120 | + self, |
| 121 | + firstColumnFileNames, |
| 122 | + secondColumnFileNames, |
| 123 | + thirdColumnFileNames, |
| 124 | + firstColumnArrowMap={}, |
| 125 | + secondColumnArrowMap={}, |
| 126 | + thirdColumnArrowMap={}, |
| 127 | + ): |
| 128 | + for file in self.files: |
| 129 | + if file in [x.a_path for x in self.repo.index.diff("HEAD")]: |
| 130 | + secondColumnFileNames.add(file) |
| 131 | + secondColumnArrowMap[file] = m.Arrow( |
| 132 | + stroke_width=3, color=self.fontColor |
| 133 | + ) |
| 134 | + else: |
| 135 | + firstColumnFileNames.add(file) |
| 136 | + firstColumnArrowMap[file] = m.Arrow( |
| 137 | + stroke_width=3, color=self.fontColor |
| 138 | + ) |
| 139 | + |
| 140 | + thirdColumnFileNames.add(file) |
0 commit comments