Skip to content

Commit 76ea235

Browse files
phillipwoodgitster
authored andcommitted
rebase -i --keep-empty: don't prune empty commits
If there are empty commits on the left hand side of $upstream...HEAD then the empty commits on the right hand side that we want to keep are pruned by --cherry-pick. Fix this by using --cherry-mark instead of --cherry-pick and keeping the commits that are empty or are not marked as cherry-picks. Signed-off-by: Phillip Wood <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent bb2ac4f commit 76ea235

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

sequencer.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2470,7 +2470,7 @@ int sequencer_make_script(FILE *out, int argc, const char **argv,
24702470
init_revisions(&revs, NULL);
24712471
revs.verbose_header = 1;
24722472
revs.max_parents = 1;
2473-
revs.cherry_pick = 1;
2473+
revs.cherry_mark = 1;
24742474
revs.limited = 1;
24752475
revs.reverse = 1;
24762476
revs.right_only = 1;
@@ -2495,8 +2495,12 @@ int sequencer_make_script(FILE *out, int argc, const char **argv,
24952495
return error(_("make_script: error preparing revisions"));
24962496

24972497
while ((commit = get_revision(&revs))) {
2498+
int is_empty = is_original_commit_empty(commit);
2499+
2500+
if (!is_empty && (commit->object.flags & PATCHSAME))
2501+
continue;
24982502
strbuf_reset(&buf);
2499-
if (!keep_empty && is_original_commit_empty(commit))
2503+
if (!keep_empty && is_empty)
25002504
strbuf_addf(&buf, "%c ", comment_line_char);
25012505
strbuf_addf(&buf, "%s %s ", insn,
25022506
oid_to_hex(&commit->object.oid));

t/t3421-rebase-topology-linear.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ test_run_rebase () {
215215
}
216216
test_run_rebase success ''
217217
test_run_rebase failure -m
218-
test_run_rebase failure -i
218+
test_run_rebase success -i
219219
test_run_rebase failure -p
220220

221221
# m

0 commit comments

Comments
 (0)