Skip to content

Commit f8885b2

Browse files
Merge branch 'main' into add-support-for-webm-output
2 parents f4db88b + 84811ee commit f8885b2

File tree

6 files changed

+107
-29
lines changed

6 files changed

+107
-29
lines changed

README.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,19 +82,20 @@ $ git-sim [global options] <subcommand> [subcommand options]
8282
The `[global options]` apply to the overarching `git-sim` simulation itself, including:
8383

8484
`--light-mode`: Use a light mode color scheme instead of default dark mode.
85-
`--animate`: Instead of outputting a static image, animate the Git command behavior in a .mp4 video.
86-
`--reverse`: Display commit history in the reverse direction.
85+
`--animate`: Instead of outputting a static image, animate the Git command behavior in a .mp4 video.
86+
`--disable-auto-open, -d`: Disable the automatic opening of the image/video file after generation.
87+
`--reverse, -r`: Display commit history in the reverse direction.
8788
`--video-format`: Output format for the video file, i.e. `mp4` or `webm`. Default output format is `mp4`.
8889

8990
Animation-only global options (to be used in conjunction with `--animate`):
9091

91-
`--speed=n`: Set the multiple of animation speed of the output simulation, `n` can be an integer or float, default is 1.
92-
`--low-quality`: Render the animation in low quality to speed up creation time, recommended for non-presentation use.
93-
`--show-intro`: Add an intro sequence with custom logo and title.
94-
`--show-outro`: Add an outro sequence with custom logo and text.
95-
`--title=title`: Custom title to display at the beginning of the animation.
96-
`--logo=logo.png`: The path to a custom logo to use in the animation intro/outro.
97-
`--outro-top-text`: Custom text to display above the logo during the outro.
92+
`--speed=n`: Set the multiple of animation speed of the output simulation, `n` can be an integer or float, default is 1.
93+
`--low-quality`: Render the animation in low quality to speed up creation time, recommended for non-presentation use.
94+
`--show-intro`: Add an intro sequence with custom logo and title.
95+
`--show-outro`: Add an outro sequence with custom logo and text.
96+
`--title=title`: Custom title to display at the beginning of the animation.
97+
`--logo=logo.png`: The path to a custom logo to use in the animation intro/outro.
98+
`--outro-top-text`: Custom text to display above the logo during the outro.
9899
`--outro-bottom-text`: Custom text to display below the logo during the outro.
99100

100101
The `[subcommand options]` are like regular Git options specific to the specified subcommand (see below for a full list).
@@ -141,6 +142,7 @@ Usage: `git-sim commit -m "Commit message"`
141142
- Specify your commit message after the -m option
142143
- HEAD and the active branch will be moved to the new commit
143144
- Simulated output will show files in the staging area being included in the new commit
145+
- Supports amending the last commit with: `$ git-sim commit --amend -m "Amended commit message"`
144146

145147
![git-sim-commit_01-05-23_22-10-21](https://user-images.githubusercontent.com/49353917/210941149-d83677a1-3ab7-4880-bc0f-871b1f150087.jpg)
146148

git_sim/__main__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,11 @@ def main():
140140
type=str,
141141
default="New commit",
142142
)
143+
commit.add_argument(
144+
"--amend",
145+
help="Amend the last commit message, must be used with the -m flag",
146+
action="store_true",
147+
)
143148

144149
stash = subparsers.add_parser("stash", help="stash -h")
145150
stash.add_argument(
@@ -279,6 +284,9 @@ def main():
279284
os.path.join(config.media_dir, "images"), image_file_name
280285
)
281286
cv2.imwrite(image_file_path, image)
287+
print("Output image location:", image_file_path)
288+
else:
289+
print("Output video location:", scene.renderer.file_writer.movie_file_path)
282290

283291
if not args.disable_auto_open:
284292
try:

git_sim/git_sim_base_command.py

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ def __init__(self, scene):
1313

1414
self.drawnCommits = {}
1515
self.drawnRefs = {}
16+
self.drawnCommitIds = {}
1617
self.commits = []
1718
self.zoomOuts = 0
1819
self.toFadeOut = m.Group()
@@ -219,6 +220,9 @@ def draw_commit(
219220
)
220221
commitId.next_to(circle, m.UP)
221222

223+
if commit != "dark":
224+
self.drawnCommitIds[commit.hexsha] = commitId
225+
222226
message = m.Text(
223227
"\n".join(
224228
commitMessage[j : j + 20] for j in range(0, len(commitMessage), 20)
@@ -256,7 +260,11 @@ def build_commit_id_and_message(self, commit, dots=False):
256260
"", font="Monospace", font_size=20, color=self.scene.fontColor
257261
)
258262
commitMessage = ""
259-
elif dots and commit.hexsha == self.commits[-1].hexsha:
263+
elif (
264+
dots
265+
and self.commits[-1] != "dark"
266+
and commit.hexsha == self.commits[-1].hexsha
267+
):
260268
commitId = m.Text(
261269
"...", font="Monospace", font_size=20, color=self.scene.fontColor
262270
)
@@ -297,13 +305,26 @@ def draw_head(self, commit, commitId):
297305

298306
def draw_branch(self, commit):
299307
x = 0
300-
branches = [branch.name for branch in self.repo.heads]
308+
309+
remote_tracking_branches = self.get_remote_tracking_branches()
310+
311+
branches = [branch.name for branch in self.repo.heads] + list(
312+
remote_tracking_branches.keys()
313+
)
314+
301315
for selected_branch in self.selected_branches:
302316
branches.insert(0, branches.pop(branches.index(selected_branch)))
303317

304318
for branch in branches:
305-
306-
if commit.hexsha == self.repo.heads[branch].commit.hexsha:
319+
# Use forward slash to check if branch is local or remote tracking
320+
# and draw the branch label if its hexsha matches the current commit
321+
if (
322+
"/" not in branch # local branch
323+
and commit.hexsha == self.repo.heads[branch].commit.hexsha
324+
) or (
325+
"/" in branch # remote tracking branch
326+
and commit.hexsha == remote_tracking_branches[branch]
327+
):
307328
branchText = m.Text(
308329
branch, font="Monospace", font_size=20, color=self.scene.fontColor
309330
)
@@ -924,6 +945,15 @@ def draw_dark_ref(self):
924945
def trim_path(self, path):
925946
return (path[:5] + "..." + path[-15:]) if len(path) > 20 else path
926947

948+
def get_remote_tracking_branches(self):
949+
remote_refs = [remote.refs for remote in self.repo.remotes]
950+
remote_tracking_branches = {}
951+
for reflist in remote_refs:
952+
for ref in reflist:
953+
if "HEAD" not in ref.name and ref.name not in remote_tracking_branches:
954+
remote_tracking_branches[ref.name] = ref.commit.hexsha
955+
return remote_tracking_branches
956+
927957

928958
class DottedLine(m.Line):
929959
def __init__(self, *args, dot_spacing=0.4, dot_kwargs={}, **kwargs):

git_sim/git_sim_commit.py

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,38 +11,69 @@ class GitSimCommit(GitSimBaseCommand):
1111
def __init__(self, scene):
1212
super().__init__(scene)
1313
self.maxrefs = 2
14-
self.defaultNumCommits = 4
15-
self.numCommits = 4
14+
self.defaultNumCommits = 4 if not self.scene.args.amend else 5
15+
self.numCommits = 4 if not self.scene.args.amend else 5
1616
self.hide_first_tag = True
1717

1818
try:
1919
self.selected_branches.append(self.repo.active_branch.name)
2020
except TypeError:
2121
pass
2222

23+
if self.scene.args.amend and self.scene.args.message == "New commit":
24+
print(
25+
"git-sim error: The --amend flag must be used with the -m flag to specify the amended commit message."
26+
)
27+
sys.exit(1)
28+
2329
def execute(self):
2430
print(
2531
"Simulating: git "
2632
+ self.scene.args.subcommand
33+
+ (" --amend" if self.scene.args.amend else "")
2734
+ ' -m "'
2835
+ self.scene.args.message
2936
+ '"'
3037
)
3138

3239
self.show_intro()
3340
self.get_commits()
41+
42+
if self.scene.args.amend:
43+
tree = self.repo.tree()
44+
amended = git.Commit.create_from_tree(
45+
self.repo,
46+
tree,
47+
self.scene.args.message,
48+
)
49+
self.commits[0] = amended
50+
3451
self.parse_commits(self.commits[self.i])
3552
self.center_frame_on_commit(self.commits[0])
36-
self.setup_and_draw_parent(self.commits[0], self.scene.args.message)
53+
54+
if not self.scene.args.amend:
55+
self.setup_and_draw_parent(self.commits[0], self.scene.args.message)
56+
else:
57+
self.draw_ref(self.commits[0], self.drawnCommitIds[amended.hexsha])
58+
self.draw_ref(
59+
self.commits[0],
60+
self.drawnRefs["HEAD"],
61+
text=self.repo.active_branch.name,
62+
color=m.GREEN,
63+
)
64+
3765
self.recenter_frame()
3866
self.scale_frame()
39-
self.reset_head_branch("abcdef")
40-
self.vsplit_frame()
41-
self.setup_and_draw_zones(
42-
first_column_name="Working directory",
43-
second_column_name="Staging area",
44-
third_column_name="New commit",
45-
)
67+
68+
if not self.scene.args.amend:
69+
self.reset_head_branch("abcdef")
70+
self.vsplit_frame()
71+
self.setup_and_draw_zones(
72+
first_column_name="Working directory",
73+
second_column_name="Staging area",
74+
third_column_name="New commit",
75+
)
76+
4677
self.fadeout()
4778
self.show_outro()
4879

git_sim/git_sim_merge.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,17 @@ def execute(self):
5656
self.orig_commits = self.commits
5757
self.get_commits(start=self.scene.args.branch[0])
5858

59-
if self.scene.args.branch[0] in self.repo.git.branch(
60-
"--contains", self.orig_commits[0].hexsha
61-
):
62-
self.ff = True
59+
# Use forward slash to determine if supplied branch arg is local or remote tracking branch
60+
if "/" not in self.scene.args.branch[0]:
61+
if self.scene.args.branch[0] in self.repo.git.branch(
62+
"--contains", self.orig_commits[0].hexsha
63+
):
64+
self.ff = True
65+
else:
66+
if self.scene.args.branch[0] in self.repo.git.branch(
67+
"-r", "--contains", self.orig_commits[0].hexsha
68+
):
69+
self.ff = True
6370

6471
if self.ff:
6572
self.get_commits(start=self.scene.args.branch[0])
@@ -83,7 +90,7 @@ def execute(self):
8390
)
8491
self.draw_ref(
8592
self.commits[0],
86-
self.drawnRefs["HEAD"] if self.scene.args.no_ff else self.topref,
93+
self.drawnRefs["HEAD"],
8794
text=self.repo.active_branch.name,
8895
color=m.GREEN,
8996
)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setuptools.setup(
77
name="git-sim",
8-
version="0.1.6",
8+
version="0.1.7",
99
author="Jacob Stopak",
1010
author_email="jacob@initialcommit.io",
1111
description="Simulate Git commands on your own repos by generating an image (default) or video visualization depicting the command's behavior.",

0 commit comments

Comments
 (0)