Skip to content

Commit 3af7e37

Browse files
committed
Add git cherry-pick --keep-redundant-commits
Signed-off-by: Edward Yang <[email protected]> ghstack-source-id: 95ba1cc ghstack-comment-id: 3356766430 Pull-Request: #301
1 parent c28491a commit 3af7e37

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

src/ghstack/cherry_pick.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ def main(
1414
sh: ghstack.shell.Shell,
1515
remote_name: str,
1616
stack: bool = False,
17+
keep_redundant_commits: bool = False,
1718
) -> None:
1819

1920
params = ghstack.github_utils.parse_pull_request(
@@ -56,10 +57,18 @@ def main(
5657

5758
logging.info(f"Cherry-picking {len(commit_list)} commits from stack")
5859
for commit in commit_list:
59-
sh.git("cherry-pick", commit)
60+
args = ["cherry-pick"]
61+
if keep_redundant_commits:
62+
args.append("--keep-redundant-commits")
63+
args.append(commit)
64+
sh.git(*args)
6065
logging.info(f"Cherry-picked {commit}")
6166
else:
6267
# Cherry-pick just the single commit
6368
remote_orig_ref = remote_name + "/" + orig_ref
64-
sh.git("cherry-pick", remote_orig_ref)
69+
args = ["cherry-pick"]
70+
if keep_redundant_commits:
71+
args.append("--keep-redundant-commits")
72+
args.append(remote_orig_ref)
73+
sh.git(*args)
6574
logging.info(f"Cherry-picked {orig_ref}")

src/ghstack/cli.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,13 @@ def checkout(pull_request: str) -> None:
134134
is_flag=True,
135135
help="Cherry-pick all commits from the commit to the merge-base with main branch",
136136
)
137+
@click.option(
138+
"--keep-redundant-commits",
139+
is_flag=True,
140+
help="Keep redundant commits when cherry-picking (passed to git cherry-pick)",
141+
)
137142
@click.argument("pull_request", metavar="PR")
138-
def cherry_pick(stack: bool, pull_request: str) -> None:
143+
def cherry_pick(stack: bool, keep_redundant_commits: bool, pull_request: str) -> None:
139144
"""
140145
Cherry-pick a PR
141146
"""
@@ -146,6 +151,7 @@ def cherry_pick(stack: bool, pull_request: str) -> None:
146151
sh=shell,
147152
remote_name=config.remote_name,
148153
stack=stack,
154+
keep_redundant_commits=keep_redundant_commits,
149155
)
150156

151157

src/ghstack/test_prelude.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,14 +240,15 @@ def gh_unlink() -> None:
240240
)
241241

242242

243-
def gh_cherry_pick(pull_request: str, stack: bool = False) -> None:
243+
def gh_cherry_pick(pull_request: str, stack: bool = False, keep_redundant_commits: bool = False) -> None:
244244
self = CTX
245245
return ghstack.cherry_pick.main(
246246
pull_request=pull_request,
247247
github=self.github,
248248
sh=self.sh,
249249
remote_name="origin",
250250
stack=stack,
251+
keep_redundant_commits=keep_redundant_commits,
251252
)
252253

253254

0 commit comments

Comments
 (0)