Skip to content

Commit df19c31

Browse files
Add -m option to merge subcommand to allow user to set commit message
Signed-off-by: Jacob Stopak <jacob@initialcommit.io>
1 parent 46de788 commit df19c31

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ Usage: `git-sim restore <file 1> <file 2> ... <file n>`
204204
Usage: `git-sim commit -m "Commit message"`
205205

206206
- Simulated output will show the new commit added to the tip of the active branch
207-
- Specify your commit message after the -m option
207+
- Specify a commit message with the `-m` option
208208
- HEAD and the active branch will be moved to the new commit
209209
- Simulated output will show files in the staging area being included in the new commit
210210
- Supports amending the last commit with: `$ git-sim commit --amend -m "Amended commit message"`
@@ -256,12 +256,14 @@ Usage: `git-sim revert <to-revert>`
256256
![git-sim-revert_01-05-23_22-16-59](https://user-images.githubusercontent.com/49353917/210941979-6db8b55c-2881-41d8-9e2e-6263b1dece13.jpg)
257257

258258
### git merge
259-
Usage: `git-sim merge <branch>`
259+
Usage: `git-sim merge <branch> [-m "Commit message"] [--no-ff]`
260260

261261
- Specify `<branch>` as the branch name to merge into the active branch
262+
- If desired, specify a commit message with the `-m` option
262263
- Simulated output will depict a fast-forward merge if possible
263264
- Otherwise, a three-way merge will be depicted
264265
- To force a merge commit when a fast-forward is possible, use `--no-ff`
266+
- If merge fails due to merge conflicts, the conflicting files are displayed
265267

266268
![git-sim-merge_01-05-23_09-44-46](https://user-images.githubusercontent.com/49353917/210942030-c7229488-571a-4943-a1f4-c6e4a0c8ccf3.jpg)
267269

git_sim/commands.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,16 @@ def merge(
153153
"--no-ff",
154154
help="Simulate creation of a merge commit in all cases, even when the merge could instead be resolved as a fast-forward",
155155
),
156+
message: str = typer.Option(
157+
"Merge commit",
158+
"--message",
159+
"-m",
160+
help="The commit message of the new merge commit",
161+
),
156162
):
157163
from git_sim.merge import Merge
158164

159-
scene = Merge(branch=branch, no_ff=no_ff)
165+
scene = Merge(branch=branch, no_ff=no_ff, message=message)
160166
handle_animations(scene=scene)
161167

162168

git_sim/merge.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@
1313

1414

1515
class Merge(GitSimBaseCommand):
16-
def __init__(self, branch: str, no_ff: bool):
16+
def __init__(self, branch: str, no_ff: bool, message: str):
1717
super().__init__()
1818
self.branch = branch
1919
self.no_ff = no_ff
20+
self.message = message
2021

2122
try:
2223
git.repo.fun.rev_parse(self.repo, self.branch)
@@ -76,7 +77,7 @@ def construct(self):
7677

7778
if self.no_ff:
7879
self.center_frame_on_commit(branch_commit)
79-
commitId = self.setup_and_draw_parent(branch_commit, "Merge commit")
80+
commitId = self.setup_and_draw_parent(branch_commit, self.message)
8081

8182
# If pre-merge HEAD is on screen, drawn an arrow to it as 2nd parent
8283
if head_commit.hexsha in self.drawnCommits:
@@ -129,7 +130,7 @@ def construct(self):
129130
self.center_frame_on_commit(head_commit)
130131
self.setup_and_draw_parent(
131132
head_commit,
132-
"Merge commit",
133+
self.message,
133134
shift=2 * m.DOWN,
134135
draw_arrow=False,
135136
color=m.GRAY,

0 commit comments

Comments
 (0)