Skip to content

Commit 62095ba

Browse files
Merge branch 'main' into switch
Signed-off-by: Jacob Stopak <jacob@initialcommit.io>
2 parents daf9f97 + 6a30249 commit 62095ba

19 files changed

Lines changed: 443 additions & 233 deletions

README.md

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Example: `$ git-sim merge <branch>`
2828
- Run a one-liner git-sim command in the terminal to generate a custom Git command visualization (.jpg) from your repo
2929
- Supported commands: `log`, `status`, `add`, `restore`, `commit`, `stash`, `branch`, `tag`, `reset`, `revert`, `merge`, `rebase`, `cherry-pick`
3030
- Generate an animated video (.mp4) instead of a static image using the `--animate` flag (note: significant performance slowdown, it is recommended to use `--low-quality` to speed up testing and remove when ready to generate presentation-quality video)
31+
- Color commits by parameter, such as author the `--color-by=author` option
3132
- Choose between dark mode (default) and light mode
3233
- Specify output formats of either jpg, png, mp4, or webm
3334
- Combine with bundled command [git-dummy](https://github.com/initialcommit-com/git-dummy) to generate a dummy Git repo and then simulate operations on it
@@ -133,13 +134,20 @@ $ git-sim [global options] <subcommand> [subcommand options]
133134

134135
The `[global options]` apply to the overarching `git-sim` simulation itself, including:
135136

136-
`--light-mode`: Use a light mode color scheme instead of default dark mode.
137+
`-n <number>`: Number of commits to display from each branch head.
138+
`--all`: Display all local branches in the log output.
137139
`--animate`: Instead of outputting a static image, animate the Git command behavior in a .mp4 video.
140+
`--color-by author`: Color commits by parameter, such as author.
141+
`--invert-branches`: Invert positioning of branches by reversing order of multiple parents where applicable.
142+
`--hide-merged-branches`: Hide commits from merged branches, i.e. only display mainline commits.
138143
`--media-dir`: The path at which to store the simulated output media files.
139144
`-d`: Disable the automatic opening of the image/video file after generation. Useful to avoid errors in console mode with no GUI.
145+
`--light-mode`: Use a light mode color scheme instead of default dark mode.
140146
`--reverse, -r`: Display commit history in the reverse direction.
141147
`--img-format`: Output format for the image file, i.e. `jpg` or `png`. Default output format is `jpg`.
142-
`--stdout`: Write raw image data to stdout while suppressing all other program output.
148+
`--stdout`: Write raw image data to stdout while suppressing all other program output.
149+
`--output-only-path`: Only output the path to the generated media file to stdout. Useful for other programs to ingest.
150+
`--quiet, -q`: Suppress all output except errors.
143151

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

@@ -158,9 +166,11 @@ The `[subcommand options]` are like regular Git options specific to the specifie
158166
The following is a list of Git commands that can be simulated and their corresponding options/flags.
159167

160168
### git log
161-
Usage: `git-sim log`
169+
Usage: `git-sim log [-n <number>] [--all]`
162170

163171
- Simulated output will show the most recent 5 commits on the active branch by default
172+
- Use `-n <number>` to set number of commits to display from each branch head
173+
- Set `--all` to display all local branches in the log output
164174

165175
![git-sim-log_01-05-23_22-02-39](https://user-images.githubusercontent.com/49353917/210940300-aadd14c6-72ab-4529-a1be-b494ed5dd4c9.jpg)
166176

@@ -445,7 +455,7 @@ $ docker build -t git-sim .
445455
Optional: On MacOS / Linux / or GitBash in Windows, create an alias for the long docker command so your can run it as a normal `git-sim` command. To do so add the following line to your `.bashrc` or equivalent, then restart your terminal:
446456

447457
```bash
448-
git-sim() { docker run --rm -v $(pwd):/usr/src/git-sim git-sim "$@" }
458+
git-sim() { docker run --rm -v $(pwd):/usr/src/git-sim git-sim "$@"; }
449459
```
450460

451461
This will enable you to run git-sim subcommands as [described above](#commands).

git_sim/__main__.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ def main(
3333
settings.animate,
3434
help="Animate the simulation and output as an mp4 video",
3535
),
36+
n: int = typer.Option(
37+
settings.n,
38+
"-n",
39+
help="Number of commits to display from each branch head",
40+
),
3641
auto_open: bool = typer.Option(
3742
settings.auto_open,
3843
"--auto-open",
@@ -108,8 +113,35 @@ def main(
108113
settings.stdout,
109114
help="Write raw image data to stdout while suppressing all other program output",
110115
),
116+
output_only_path: bool = typer.Option(
117+
settings.output_only_path,
118+
help="Only output the path to the generated media file to stdout (useful for other programs to ingest)",
119+
),
120+
quiet: bool = typer.Option(
121+
settings.quiet,
122+
"--quiet",
123+
"-q",
124+
help="Suppress all output except errors",
125+
),
126+
invert_branches: bool = typer.Option(
127+
settings.invert_branches,
128+
help="Invert positioning of branches by reversing order of multiple parents where applicable",
129+
),
130+
hide_merged_branches: bool = typer.Option(
131+
settings.hide_merged_branches,
132+
help="Hide commits from merged branches, i.e. only display mainline commits",
133+
),
134+
all: bool = typer.Option(
135+
settings.all,
136+
help="Display all local branches in the log output",
137+
),
138+
color_by: str = typer.Option(
139+
settings.color_by,
140+
help="Color commits by parameter, such as author",
141+
),
111142
):
112143
settings.animate = animate
144+
settings.n = n
113145
settings.auto_open = auto_open
114146
settings.img_format = img_format
115147
settings.light_mode = light_mode
@@ -127,6 +159,12 @@ def main(
127159
settings.title = title
128160
settings.video_format = video_format
129161
settings.stdout = stdout
162+
settings.output_only_path = output_only_path
163+
settings.quiet = quiet
164+
settings.invert_branches = invert_branches
165+
settings.hide_merged_branches = hide_merged_branches
166+
settings.all = all
167+
settings.color_by = color_by
130168

131169
if sys.platform == "linux" or sys.platform == "darwin":
132170
repo_name = git.repo.Repo(

git_sim/add.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ def __init__(self, files: List[str]):
1616
self.hide_first_tag = True
1717
self.allow_no_commits = True
1818
self.files = files
19+
settings.hide_merged_branches = True
20+
self.n = self.n_default
1921

2022
try:
2123
self.selected_branches.append(self.repo.active_branch.name)
@@ -30,14 +32,13 @@ def __init__(self, files: List[str]):
3032
sys.exit()
3133

3234
def construct(self):
33-
if not settings.stdout:
35+
if not settings.stdout and not settings.output_only_path and not settings.quiet:
3436
print(
3537
f"{settings.INFO_STRING} {type(self).__name__.lower()} {' '.join(self.files)}"
3638
)
3739

3840
self.show_intro()
39-
self.get_commits()
40-
self.parse_commits(self.commits[0])
41+
self.parse_commits()
4142
self.recenter_frame()
4243
self.scale_frame()
4344
self.vsplit_frame()
@@ -89,5 +90,6 @@ def add(
8990
help="The names of one or more files to add to Git's staging area",
9091
)
9192
):
93+
settings.hide_first_tag = True
9294
scene = Add(files=files)
9395
handle_animations(scene=scene)

git_sim/animations.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,23 @@ def handle_animations(scene: Scene) -> None:
4747
os.path.join(settings.media_dir, "images"), image_file_name
4848
)
4949
cv2.imwrite(image_file_path, image)
50-
if not settings.stdout:
50+
if (
51+
not settings.stdout
52+
and not settings.output_only_path
53+
and not settings.quiet
54+
):
5155
print("Output image location:", image_file_path)
52-
if settings.stdout:
56+
elif (
57+
not settings.stdout and settings.output_only_path and not settings.quiet
58+
):
59+
print(image_file_path)
60+
if settings.stdout and not settings.quiet:
5361
sys.stdout.buffer.write(cv2.imencode(".jpg", image)[1].tobytes())
5462
else:
55-
print("Output video location:", scene.renderer.file_writer.movie_file_path)
63+
if not settings.stdout and not settings.output_only_path and not settings.quiet:
64+
print("Output video location:", scene.renderer.file_writer.movie_file_path)
65+
elif not settings.stdout and settings.output_only_path and not settings.quiet:
66+
print(scene.renderer.file_writer.movie_file_path)
5667

5768
if settings.auto_open and not settings.stdout:
5869
try:

git_sim/branch.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@ def __init__(self, name: str):
1212
self.name = name
1313

1414
def construct(self):
15-
if not settings.stdout:
15+
if not settings.stdout and not settings.output_only_path and not settings.quiet:
1616
print(f"{settings.INFO_STRING} {type(self).__name__.lower()} {self.name}")
1717

1818
self.show_intro()
19-
self.get_commits()
20-
self.parse_commits(self.commits[0])
21-
self.recenter_frame()
22-
self.scale_frame()
19+
self.parse_commits()
20+
self.parse_all()
21+
self.center_frame_on_commit(self.get_commit())
2322

2423
branchText = m.Text(
2524
self.name,
@@ -48,6 +47,9 @@ def construct(self):
4847
self.toFadeOut.add(branchRec, branchText)
4948
self.drawnRefs[self.name] = fullbranch
5049

50+
self.recenter_frame()
51+
self.scale_frame()
52+
self.color_by()
5153
self.fadeout()
5254
self.show_outro()
5355

git_sim/cherrypick.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def __init__(self, commit: str, edit: str):
3434
pass
3535

3636
def construct(self):
37-
if not settings.stdout:
37+
if not settings.stdout and not settings.output_only_path and not settings.quiet:
3838
print(
3939
f"{settings.INFO_STRING} cherry-pick {self.commit}"
4040
+ ((' -e "' + self.edit + '"') if self.edit else "")
@@ -53,20 +53,21 @@ def construct(self):
5353
sys.exit(1)
5454

5555
self.show_intro()
56-
self.get_commits()
57-
self.parse_commits(self.commits[0])
58-
self.orig_commits = self.commits
59-
self.get_commits(start=self.commit)
60-
self.parse_commits(self.commits[0], shift=4 * m.DOWN)
61-
self.center_frame_on_commit(self.orig_commits[0])
56+
head_commit = self.get_commit()
57+
self.parse_commits(head_commit)
58+
cherry_picked_commit = self.get_commit(self.commit)
59+
self.parse_commits(cherry_picked_commit, shift=4 * m.DOWN)
60+
self.parse_all()
61+
self.center_frame_on_commit(head_commit)
6262
self.setup_and_draw_parent(
63-
self.orig_commits[0],
64-
self.edit if self.edit else self.commits[0].message,
63+
head_commit,
64+
self.edit if self.edit else cherry_picked_commit.message,
6565
)
66-
self.draw_arrow_between_commits(self.commits[0].hexsha, "abcdef")
66+
self.draw_arrow_between_commits(cherry_picked_commit.hexsha, "abcdef")
6767
self.recenter_frame()
6868
self.scale_frame()
6969
self.reset_head_branch("abcdef")
70+
self.color_by(offset=2)
7071
self.fadeout()
7172
self.show_outro()
7273

git_sim/commit.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ def __init__(self, message: str, amend: bool):
1515
self.message = message
1616
self.amend = amend
1717

18-
self.defaultNumCommits = 4 if not self.amend else 5
19-
self.numCommits = 4 if not self.amend else 5
18+
self.n_default = 4 if not self.amend else 5
19+
self.n = self.n_default
20+
2021
self.hide_first_tag = True
22+
settings.hide_merged_branches = True
2123

2224
try:
2325
self.selected_branches.append(self.repo.active_branch.name)
@@ -31,7 +33,7 @@ def __init__(self, message: str, amend: bool):
3133
sys.exit(1)
3234

3335
def construct(self):
34-
if not settings.stdout:
36+
if not settings.stdout and not settings.output_only_path and not settings.quiet:
3537
print(
3638
f"{settings.INFO_STRING } {type(self).__name__.lower()} {'--amend ' if self.amend else ''}"
3739
+ '-m "'
@@ -40,7 +42,7 @@ def construct(self):
4042
)
4143

4244
self.show_intro()
43-
self.get_commits()
45+
head_commit = self.get_commit()
4446

4547
if self.amend:
4648
tree = self.repo.tree()
@@ -49,17 +51,17 @@ def construct(self):
4951
tree,
5052
self.message,
5153
)
52-
self.commits[0] = amended
54+
head_commit = amended
5355

54-
self.parse_commits(self.commits[self.i])
55-
self.center_frame_on_commit(self.commits[0])
56+
self.parse_commits(head_commit)
57+
self.center_frame_on_commit(head_commit)
5658

5759
if not self.amend:
58-
self.setup_and_draw_parent(self.commits[0], self.message)
60+
self.setup_and_draw_parent(head_commit, self.message)
5961
else:
60-
self.draw_ref(self.commits[0], self.drawnCommitIds[amended.hexsha])
62+
self.draw_ref(head_commit, self.drawnCommitIds[amended.hexsha])
6163
self.draw_ref(
62-
self.commits[0],
64+
head_commit,
6365
self.drawnRefs["HEAD"],
6466
text=self.repo.active_branch.name,
6567
color=m.GREEN,
@@ -114,5 +116,6 @@ def commit(
114116
help="Amend the last commit message, must be used with the --message flag",
115117
),
116118
):
119+
settings.hide_first_tag = True
117120
scene = Commit(message=message, amend=amend)
118121
handle_animations(scene=scene)

0 commit comments

Comments
 (0)