In the previous patches, we implemented the basic functionality of the `git rebase -i --rebase-merges` command, in particular the `merge` command to create merge commits in the sequencer. The interactive rebase is a lot more these days, though, than a simple cherry-pick in a loop. For example, it calls the post-rewrite hook (if any) after rebasing with a mapping of the old->new commits. This patch implements the post-rewrite handling for the `merge` command we just introduced. The other commands that were added recently (`label` and `reset`) do not create new commits, therefore post-rewrite hooks do not need to handle them. Signed-off-by: Johannes Schindelin <johannes.schindelin@xxxxxx> --- sequencer.c | 7 +++++-- t/t3430-rebase-merges.sh | 25 +++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/sequencer.c b/sequencer.c index 422c71db975..878ff449fe8 100644 --- a/sequencer.c +++ b/sequencer.c @@ -3012,10 +3012,13 @@ static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts) res = do_label(item->arg, item->arg_len); else if (item->command == TODO_RESET) res = do_reset(item->arg, item->arg_len, opts); - else if (item->command == TODO_MERGE) + else if (item->command == TODO_MERGE) { res = do_merge(item->commit, item->arg, item->arg_len, item->flags, opts); - else if (!is_noop(item->command)) + if (item->commit) + record_in_rewritten(&item->commit->object.oid, + peek_command(todo_list, 1)); + } else if (!is_noop(item->command)) return error(_("unknown command %d"), item->command); todo_list->current++; diff --git a/t/t3430-rebase-merges.sh b/t/t3430-rebase-merges.sh index 95f99d965c1..392c1136973 100755 --- a/t/t3430-rebase-merges.sh +++ b/t/t3430-rebase-merges.sh @@ -157,4 +157,29 @@ test_expect_success 'refs/rewritten/* is worktree-local' ' test_cmp_rev HEAD "$(cat wt/b)" ' +test_expect_success 'post-rewrite hook and fixups work for merges' ' + git checkout -b post-rewrite && + test_commit same1 && + git reset --hard HEAD^ && + test_commit same2 && + git merge -m "to fix up" same1 && + echo same old same old >same2.t && + test_tick && + git commit --fixup HEAD same2.t && + fixup="$(git rev-parse HEAD)" && + + mkdir -p .git/hooks && + test_when_finished "rm .git/hooks/post-rewrite" && + echo "cat >actual" | write_script .git/hooks/post-rewrite && + + test_tick && + git rebase -i --autosquash -r HEAD^^^ && + printf "%s %s\n%s %s\n%s %s\n%s %s\n" >expect $(git rev-parse \ + $fixup^^2 HEAD^2 \ + $fixup^^ HEAD^ \ + $fixup^ HEAD \ + $fixup HEAD) && + test_cmp expect actual +' + test_done -- 2.17.0.windows.1.4.g7e4058d72e3