From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS31976 209.132.180.0/23 X-Spam-Status: No, score=-3.1 required=3.0 tests=AWL,BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI shortcircuit=no autolearn=ham autolearn_force=no version=3.4.0 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by dcvr.yhbt.net (Postfix) with ESMTP id 6FE731F404 for ; Tue, 10 Apr 2018 12:30:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753101AbeDJMaW (ORCPT ); Tue, 10 Apr 2018 08:30:22 -0400 Received: from mout.gmx.net ([212.227.15.18]:36247 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752585AbeDJMaT (ORCPT ); Tue, 10 Apr 2018 08:30:19 -0400 Received: from minint-aivcfq2.fareast.corp.microsoft.com ([37.201.195.115]) by mail.gmx.com (mrgmx001 [212.227.17.190]) with ESMTPSA (Nemesis) id 0MHoWj-1f2q8v10Cj-003fl2; Tue, 10 Apr 2018 14:30:12 +0200 Date: Tue, 10 Apr 2018 14:30:11 +0200 (DST) From: Johannes Schindelin X-X-Sender: virtualbox@MININT-6BKU6QN.europe.corp.microsoft.com To: git@vger.kernel.org cc: Junio C Hamano , Jacob Keller , Stefan Beller , Philip Oakley , Eric Sunshine , Phillip Wood , Igor Djordjevic , Johannes Sixt , Sergey Organov Subject: [PATCH v6 11/15] sequencer: handle post-rewrite for merge commands In-Reply-To: Message-ID: <3316ce1ee802d0bded8c47e3ad2abd00ea63956c.1523362469.git.johannes.schindelin@gmx.de> References: User-Agent: Alpine 2.21.1 (DEB 209 2017-03-23) MIME-Version: 1.0 Content-Type: text/plain; charset=US-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B9E+vtENfLFQxor2w6rlByHzXZBPvkTc+Z9ON FE30+42Nc101xaL2rSDz9pI5ir32sIlmiN60g2DRNj3yQs8qqE= Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org 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 --- 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