Skip to content

Commit 0baf677

Browse files
Merge branch 'diverse-branching-structure'
Signed-off-by: Jacob Stopak <[email protected]>
2 parents d8cbb35 + 7fb6dc1 commit 0baf677

17 files changed

+283
-202
lines changed

README.md

+8-2
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,14 @@ $ git-sim [global options] <subcommand> [subcommand options]
133133

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

136-
`--light-mode`: Use a light mode color scheme instead of default dark mode.
136+
`-n <number>`: Number of commits to display from each branch head.
137+
`--all`: Display all local branches in the log output.
137138
`--animate`: Instead of outputting a static image, animate the Git command behavior in a .mp4 video.
139+
`--invert-branches`: Invert positioning of branches by reversing order of multiple parents where applicable.
140+
`--hide-merged-branches`: Hide commits from merged branches, i.e. only display mainline commits.
138141
`--media-dir`: The path at which to store the simulated output media files.
139142
`-d`: Disable the automatic opening of the image/video file after generation. Useful to avoid errors in console mode with no GUI.
143+
`--light-mode`: Use a light mode color scheme instead of default dark mode.
140144
`--reverse, -r`: Display commit history in the reverse direction.
141145
`--img-format`: Output format for the image file, i.e. `jpg` or `png`. Default output format is `jpg`.
142146
`--stdout`: Write raw image data to stdout while suppressing all other program output.
@@ -160,9 +164,11 @@ The `[subcommand options]` are like regular Git options specific to the specifie
160164
The following is a list of Git commands that can be simulated and their corresponding options/flags.
161165

162166
### git log
163-
Usage: `git-sim log`
167+
Usage: `git-sim log [-n <number>] [--all]`
164168

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

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

git_sim/__main__.py

+20
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ def main(
3232
settings.animate,
3333
help="Animate the simulation and output as an mp4 video",
3434
),
35+
n: int = typer.Option(
36+
settings.n,
37+
"-n",
38+
help="Number of commits to display from each branch head",
39+
),
3540
auto_open: bool = typer.Option(
3641
settings.auto_open,
3742
"--auto-open",
@@ -116,9 +121,21 @@ def main(
116121
"--quiet",
117122
"-q",
118123
help="Suppress all output except errors",
124+
invert_branches: bool = typer.Option(
125+
settings.invert_branches,
126+
help="Invert positioning of branches by reversing order of multiple parents where applicable",
127+
),
128+
hide_merged_branches: bool = typer.Option(
129+
settings.hide_merged_branches,
130+
help="Hide commits from merged branches, i.e. only display mainline commits",
131+
),
132+
all: bool = typer.Option(
133+
settings.all,
134+
help="Display all local branches in the log output",
119135
),
120136
):
121137
settings.animate = animate
138+
settings.n = n
122139
settings.auto_open = auto_open
123140
settings.img_format = img_format
124141
settings.light_mode = light_mode
@@ -138,6 +155,9 @@ def main(
138155
settings.stdout = stdout
139156
settings.output_only_path = output_only_path
140157
settings.quiet = quiet
158+
settings.invert_branches = invert_branches
159+
settings.hide_merged_branches = hide_merged_branches
160+
settings.all = all
141161

142162
if sys.platform == "linux" or sys.platform == "darwin":
143163
repo_name = git.repo.Repo(

git_sim/add.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ 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
1920

2021
try:
2122
self.selected_branches.append(self.repo.active_branch.name)
@@ -36,8 +37,7 @@ def construct(self):
3637
)
3738

3839
self.show_intro()
39-
self.get_commits()
40-
self.parse_commits(self.commits[0])
40+
self.parse_commits()
4141
self.recenter_frame()
4242
self.scale_frame()
4343
self.vsplit_frame()

git_sim/branch.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@ def construct(self):
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,8 @@ def construct(self):
4847
self.toFadeOut.add(branchRec, branchText)
4948
self.drawnRefs[self.name] = fullbranch
5049

50+
self.recenter_frame()
51+
self.scale_frame()
5152
self.fadeout()
5253
self.show_outro()
5354

git_sim/cherrypick.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,17 @@ 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")

git_sim/commit.py

+11-9
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)
@@ -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,

0 commit comments

Comments
 (0)