Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/ghstack/cherry_pick.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def main(
sh: ghstack.shell.Shell,
remote_name: str,
stack: bool = False,
keep_redundant_commits: bool = False,
) -> None:

params = ghstack.github_utils.parse_pull_request(
Expand Down Expand Up @@ -56,10 +57,18 @@ def main(

logging.info(f"Cherry-picking {len(commit_list)} commits from stack")
for commit in commit_list:
sh.git("cherry-pick", commit)
args = ["cherry-pick"]
if keep_redundant_commits:
args.append("--keep-redundant-commits")
args.append(commit)
sh.git(*args)
logging.info(f"Cherry-picked {commit}")
else:
# Cherry-pick just the single commit
remote_orig_ref = remote_name + "/" + orig_ref
sh.git("cherry-pick", remote_orig_ref)
args = ["cherry-pick"]
if keep_redundant_commits:
args.append("--keep-redundant-commits")
args.append(remote_orig_ref)
sh.git(*args)
logging.info(f"Cherry-picked {orig_ref}")
8 changes: 7 additions & 1 deletion src/ghstack/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,13 @@ def checkout(pull_request: str) -> None:
is_flag=True,
help="Cherry-pick all commits from the commit to the merge-base with main branch",
)
@click.option(
"--keep-redundant-commits",
is_flag=True,
help="Keep redundant commits when cherry-picking (passed to git cherry-pick)",
)
@click.argument("pull_request", metavar="PR")
def cherry_pick(stack: bool, pull_request: str) -> None:
def cherry_pick(stack: bool, keep_redundant_commits: bool, pull_request: str) -> None:
"""
Cherry-pick a PR
"""
Expand All @@ -146,6 +151,7 @@ def cherry_pick(stack: bool, pull_request: str) -> None:
sh=shell,
remote_name=config.remote_name,
stack=stack,
keep_redundant_commits=keep_redundant_commits,
)


Expand Down
3 changes: 2 additions & 1 deletion src/ghstack/test_prelude.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import argparse
import atexit
import contextlib
Expand Down Expand Up @@ -240,14 +240,15 @@
)


def gh_cherry_pick(pull_request: str, stack: bool = False) -> None:
def gh_cherry_pick(pull_request: str, stack: bool = False, keep_redundant_commits: bool = False) -> None:
self = CTX
return ghstack.cherry_pick.main(
pull_request=pull_request,
github=self.github,
sh=self.sh,
remote_name="origin",
stack=stack,
keep_redundant_commits=keep_redundant_commits,
)


Expand Down
Loading