diff --git a/README.md b/README.md index d06b9aa..4c3d90a 100644 --- a/README.md +++ b/README.md @@ -186,7 +186,7 @@ Usage: `git-sim commit -m "Commit message"` ![git-sim-commit_01-05-23_22-10-21](https://user-images.githubusercontent.com/49353917/210941149-d83677a1-3ab7-4880-bc0f-871b1f150087.jpg) ### git stash -Usage: `git-sim stash ` +Usage: `git-sim stash [push|pop|apply] ` - Specify one or more `` as a *modified* working directory file, or staged file - If no `` is specified, all available working directory and staged files will be included diff --git a/git_sim/git_sim_base_command.py b/git_sim/git_sim_base_command.py index 5d1163f..8e65e80 100644 --- a/git_sim/git_sim_base_command.py +++ b/git_sim/git_sim_base_command.py @@ -591,6 +591,7 @@ def setup_and_draw_zones( firstColumnArrowMap = {} secondColumnArrowMap = {} + thirdColumnArrowMap = {} self.populate_zones( firstColumnFileNames, @@ -598,6 +599,7 @@ def setup_and_draw_zones( thirdColumnFileNames, firstColumnArrowMap, secondColumnArrowMap, + thirdColumnArrowMap, ) firstColumnFiles = m.VGroup() @@ -608,53 +610,21 @@ def setup_and_draw_zones( secondColumnFilesDict = {} thirdColumnFilesDict = {} - for i, f in enumerate(firstColumnFileNames): - text = ( - m.Text( - self.trim_path(f), - font="Monospace", - font_size=24, - color=self.fontColor, - ) - .move_to( - (firstColumnTitle.get_center()[0], horizontal2.get_center()[1], 0) - ) - .shift(m.DOWN * 0.5 * (i + 1)) - ) - firstColumnFiles.add(text) - firstColumnFilesDict[f] = text - - for j, f in enumerate(secondColumnFileNames): - text = ( - m.Text( - self.trim_path(f), - font="Monospace", - font_size=24, - color=self.fontColor, - ) - .move_to( - (secondColumnTitle.get_center()[0], horizontal2.get_center()[1], 0) - ) - .shift(m.DOWN * 0.5 * (j + 1)) - ) - secondColumnFiles.add(text) - secondColumnFilesDict[f] = text - - for h, f in enumerate(thirdColumnFileNames): - text = ( - m.Text( - self.trim_path(f), - font="Monospace", - font_size=24, - color=self.fontColor, - ) - .move_to( - (thirdColumnTitle.get_center()[0], horizontal2.get_center()[1], 0) - ) - .shift(m.DOWN * 0.5 * (h + 1)) - ) - thirdColumnFiles.add(text) - thirdColumnFilesDict[f] = text + self.create_zone_text( + firstColumnFileNames, + secondColumnFileNames, + thirdColumnFileNames, + firstColumnFiles, + secondColumnFiles, + thirdColumnFiles, + firstColumnFilesDict, + secondColumnFilesDict, + thirdColumnFilesDict, + firstColumnTitle, + secondColumnTitle, + thirdColumnTitle, + horizontal2, + ) if len(firstColumnFiles): if settings.animate: @@ -726,6 +696,26 @@ def setup_and_draw_zones( self.add(secondColumnArrowMap[filename]) self.toFadeOut.add(secondColumnArrowMap[filename]) + for filename in thirdColumnArrowMap: + thirdColumnArrowMap[filename].put_start_and_end_on( + ( + thirdColumnFilesDict[filename].get_left()[0] - 0.25, + thirdColumnFilesDict[filename].get_left()[1], + 0, + ), + ( + firstColumnFilesDict[filename].get_right()[0] + 0.25, + firstColumnFilesDict[filename].get_right()[1], + 0, + ), + ) + + if settings.animate: + self.play(m.Create(thirdColumnArrowMap[filename])) + else: + self.add(thirdColumnArrowMap[filename]) + self.toFadeOut.add(thirdColumnArrowMap[filename]) + self.toFadeOut.add(firstColumnFiles, secondColumnFiles, thirdColumnFiles) def populate_zones( @@ -735,6 +725,7 @@ def populate_zones( thirdColumnFileNames, firstColumnArrowMap={}, secondColumnArrowMap={}, + thirdColumnArrowMap={}, ): for x in self.repo.index.diff(None): if "git-sim_media" not in x.a_path: @@ -946,6 +937,71 @@ def is_remote_tracking_branch(self, branch): remote_tracking_branches[ref.name] = ref.commit.hexsha return branch in remote_tracking_branches + def create_zone_text( + self, + firstColumnFileNames, + secondColumnFileNames, + thirdColumnFileNames, + firstColumnFiles, + secondColumnFiles, + thirdColumnFiles, + firstColumnFilesDict, + secondColumnFilesDict, + thirdColumnFilesDict, + firstColumnTitle, + secondColumnTitle, + thirdColumnTitle, + horizontal2, + ): + + for i, f in enumerate(firstColumnFileNames): + text = ( + m.Text( + self.trim_path(f), + font="Monospace", + font_size=24, + color=self.fontColor, + ) + .move_to( + (firstColumnTitle.get_center()[0], horizontal2.get_center()[1], 0) + ) + .shift(m.DOWN * 0.5 * (i + 1)) + ) + firstColumnFiles.add(text) + firstColumnFilesDict[f] = text + + for j, f in enumerate(secondColumnFileNames): + text = ( + m.Text( + self.trim_path(f), + font="Monospace", + font_size=24, + color=self.fontColor, + ) + .move_to( + (secondColumnTitle.get_center()[0], horizontal2.get_center()[1], 0) + ) + .shift(m.DOWN * 0.5 * (j + 1)) + ) + secondColumnFiles.add(text) + secondColumnFilesDict[f] = text + + for h, f in enumerate(thirdColumnFileNames): + text = ( + m.Text( + self.trim_path(f), + font="Monospace", + font_size=24, + color=self.fontColor, + ) + .move_to( + (thirdColumnTitle.get_center()[0], horizontal2.get_center()[1], 0) + ) + .shift(m.DOWN * 0.5 * (h + 1)) + ) + thirdColumnFiles.add(text) + thirdColumnFilesDict[f] = text + class DottedLine(m.Line): def __init__(self, *args, dot_spacing=0.4, dot_kwargs={}, **kwargs): diff --git a/git_sim/stash.py b/git_sim/stash.py index 147b0b5..63718aa 100644 --- a/git_sim/stash.py +++ b/git_sim/stash.py @@ -1,4 +1,5 @@ import sys +from enum import Enum import manim as m import typer @@ -9,34 +10,49 @@ from git_sim.settings import settings +class StashSubCommand(Enum): + POP = "pop" + APPLY = "apply" + PUSH = "push" + + class Stash(GitSimBaseCommand): - def __init__(self, files: List[str]): + def __init__(self, files: List[str], command: StashSubCommand): super().__init__() self.hide_first_tag = True self.files = files self.no_files = True if not self.files else False + self.command = command try: self.selected_branches.append(self.repo.active_branch.name) except TypeError: pass - for file in self.files: - if file not in [x.a_path for x in self.repo.index.diff(None)] + [ - 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() + if self.command in [StashSubCommand.PUSH, None]: + for file in self.files: + if file not in [x.a_path for x in self.repo.index.diff(None)] + [ + 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() - if not self.files: - self.files = [x.a_path for x in self.repo.index.diff(None)] + [ - y.a_path for y in self.repo.index.diff("HEAD") - ] + if not self.files: + self.files = [x.a_path for x in self.repo.index.diff(None)] + [ + y.a_path for y in self.repo.index.diff("HEAD") + ] + elif self.files: + if not settings.stdout: + print( + "Files are not required in apply/pop subcommand. Ignoring the file list....." + ) def construct(self): if not settings.stdout: print( - f"{settings.INFO_STRING } {type(self).__name__.lower()} {' '.join(self.files) if not self.no_files else ''}" + f"{settings.INFO_STRING } {type(self).__name__.lower()} {self.command.value if self.command else ''} {' '.join(self.files) if not self.no_files else ''}" ) self.show_intro() @@ -53,6 +69,76 @@ def construct(self): self.fadeout() self.show_outro() + def create_zone_text( + self, + firstColumnFileNames, + secondColumnFileNames, + thirdColumnFileNames, + firstColumnFiles, + secondColumnFiles, + thirdColumnFiles, + firstColumnFilesDict, + secondColumnFilesDict, + thirdColumnFilesDict, + firstColumnTitle, + secondColumnTitle, + thirdColumnTitle, + horizontal2, + ): + for i, f in enumerate(firstColumnFileNames): + text = ( + m.Text( + self.trim_path(f), + font="Monospace", + font_size=24, + color=self.fontColor, + ) + .move_to( + (firstColumnTitle.get_center()[0], horizontal2.get_center()[1], 0) + ) + .shift(m.DOWN * 0.5 * (i + 1)) + ) + firstColumnFiles.add(text) + firstColumnFilesDict[f] = text + + for j, f in enumerate(secondColumnFileNames): + text = ( + m.Text( + self.trim_path(f), + font="Monospace", + font_size=24, + color=self.fontColor, + ) + .move_to( + (secondColumnTitle.get_center()[0], horizontal2.get_center()[1], 0) + ) + .shift(m.DOWN * 0.5 * (j + 1)) + ) + secondColumnFiles.add(text) + secondColumnFilesDict[f] = text + + for h, f in enumerate(thirdColumnFileNames): + text = ( + m.MarkupText( + "" + + self.trim_path(f) + + "" + if self.command == StashSubCommand.POP + else self.trim_path(f), + font="Monospace", + font_size=24, + color=self.fontColor, + ) + .move_to( + (thirdColumnTitle.get_center()[0], horizontal2.get_center()[1], 0) + ) + .shift(m.DOWN * 0.5 * (h + 1)) + ) + thirdColumnFiles.add(text) + thirdColumnFilesDict[f] = text + def populate_zones( self, firstColumnFileNames, @@ -60,31 +146,53 @@ def populate_zones( thirdColumnFileNames, firstColumnArrowMap, secondColumnArrowMap, + thirdColumnArrowMap, ): - for x in self.repo.index.diff(None): - firstColumnFileNames.add(x.a_path) - for file in self.files: - if file == x.a_path: - thirdColumnFileNames.add(x.a_path) - firstColumnArrowMap[x.a_path] = m.Arrow( - stroke_width=3, color=self.fontColor - ) - for y in self.repo.index.diff("HEAD"): - secondColumnFileNames.add(y.a_path) - for file in self.files: - if file == y.a_path: - thirdColumnFileNames.add(y.a_path) - secondColumnArrowMap[y.a_path] = m.Arrow( - stroke_width=3, color=self.fontColor - ) + if self.command in [StashSubCommand.POP, StashSubCommand.APPLY]: + for x in self.repo.index.diff(None): + thirdColumnFileNames.add(x.a_path) + firstColumnFileNames.add(x.a_path) + thirdColumnArrowMap[x.a_path] = m.Arrow( + stroke_width=3, color=self.fontColor + ) + + for y in self.repo.index.diff("HEAD"): + firstColumnFileNames.add(y.a_path) + thirdColumnFileNames.add(y.a_path) + thirdColumnArrowMap[y.a_path] = m.Arrow( + stroke_width=3, color=self.fontColor + ) + + else: + for x in self.repo.index.diff(None): + firstColumnFileNames.add(x.a_path) + for file in self.files: + if file == x.a_path: + thirdColumnFileNames.add(x.a_path) + firstColumnArrowMap[x.a_path] = m.Arrow( + stroke_width=3, color=self.fontColor + ) + + for y in self.repo.index.diff("HEAD"): + secondColumnFileNames.add(y.a_path) + for file in self.files: + if file == y.a_path: + thirdColumnFileNames.add(y.a_path) + secondColumnArrowMap[y.a_path] = m.Arrow( + stroke_width=3, color=self.fontColor + ) def stash( + command: StashSubCommand = typer.Argument( + default=None, + help="Stash subcommand (push, pop, apply)", + ), files: List[str] = typer.Argument( default=None, help="The name of the file to stash changes for", - ) + ), ): - scene = Stash(files=files) + scene = Stash(files=files, command=command) handle_animations(scene=scene)