Skip to content

Commit

Permalink
Support -e, --edit option for cherry-pick subcommand to specify edite…
Browse files Browse the repository at this point in the history
…d commit message

Signed-off-by: Jacob Stopak <jacob@initialcommit.io>
  • Loading branch information
initialcommit-io committed Feb 6, 2023
1 parent e68e5e2 commit f02623d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ Usage: `git-sim rebase <new-base>`
Usage: `git-sim cherry-pick <commit>`

- Specify `<commit>` as a ref (branch name/tag) or commit ID to cherry-pick onto the active branch
- Supports editing the cherry-picked commit message with: `$ git-sim cherry-pick <commit> -e "Edited commit message"`

![git-sim-cherry-pick_01-05-23_22-23-08](https://user-images.githubusercontent.com/49353917/210942811-fa5155b1-4c6f-4afc-bea2-d39b4cd594aa.jpg)

Expand Down
6 changes: 6 additions & 0 deletions git_sim/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,12 @@ def main():
type=str,
help="The ref (branch/tag), or commit ID to simulate cherry-pick onto active branch",
)
cherrypick.add_argument(
"-e",
"--edit",
help="Specify a new commit message for the cherry-picked commit",
type=str,
)

if len(sys.argv) == 1:
parser.print_help()
Expand Down
13 changes: 11 additions & 2 deletions git_sim/git_sim_cherrypick.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@ def __init__(self, args: Namespace):
pass

def construct(self):
print("Simulating: git " + self.args.subcommand + " " + self.args.commit[0])
print(
"Simulating: git "
+ self.args.subcommand
+ " "
+ self.args.commit[0]
+ ((' -e "' + self.args.edit + '"') if self.args.edit else "")
)

if self.repo.active_branch.name in self.repo.git.branch(
"--contains", self.args.commit[0]
Expand All @@ -51,7 +57,10 @@ def construct(self):
self.get_commits(start=self.args.commit[0])
self.parse_commits(self.commits[0], shift=4 * m.DOWN)
self.center_frame_on_commit(self.orig_commits[0])
self.setup_and_draw_parent(self.orig_commits[0], self.commits[0].message)
self.setup_and_draw_parent(
self.orig_commits[0],
self.args.edit if self.args.edit else self.commits[0].message,
)
self.draw_arrow_between_commits(self.commits[0].hexsha, "abcdef")
self.recenter_frame()
self.scale_frame()
Expand Down

0 comments on commit f02623d

Please sign in to comment.