sequencer: handle post-rewrite for merge commands
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@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Johannes Schindelin committed
Apr 25, 2018 at 14:29 UTC
537e7d61359233e95d2ca6ef6b9059afca8daa81
2 files changed
+29
-1
sequencer.c
+4
-1
@@ -3074,7 +3074,10 @@ static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts)
3074
item->arg, item->arg_len,
3075
item->flags, opts)) < 0)
3076
reschedule = 1;
3077
- else if (res > 0)
3077
+ else if (item->commit)
3078
+ record_in_rewritten(&item->commit->object.oid,
3079
+ peek_command(todo_list, 1));
3080
+ if (res > 0)
3081
/* failed with merge conflicts */
3082
return error_with_patch(item->commit,
3083
item->arg,
t/t3430-rebase-merges.sh
+25
@@ -190,4 +190,29 @@ test_expect_success 'refs/rewritten/* is worktree-local' '
190
test_cmp_rev HEAD "$(cat wt/b)"
191
'
192
193
+test_expect_success 'post-rewrite hook and fixups work for merges' '
194
+ git checkout -b post-rewrite &&
195
+ test_commit same1 &&
196
+ git reset --hard HEAD^ &&
197
+ test_commit same2 &&
198
+ git merge -m "to fix up" same1 &&
199
+ echo same old same old >same2.t &&
200
+ test_tick &&
201
+ git commit --fixup HEAD same2.t &&
202
+ fixup="$(git rev-parse HEAD)" &&
203
+
204
+ mkdir -p .git/hooks &&
205
+ test_when_finished "rm .git/hooks/post-rewrite" &&
206
+ echo "cat >actual" | write_script .git/hooks/post-rewrite &&
207
+
208
+ test_tick &&
209
+ git rebase -i --autosquash -r HEAD^^^ &&
210
+ printf "%s %s\n%s %s\n%s %s\n%s %s\n" >expect $(git rev-parse \
211
+ $fixup^^2 HEAD^2 \
212
+ $fixup^^ HEAD^ \
213
+ $fixup^ HEAD \
214
+ $fixup HEAD) &&
215
+ test_cmp expect actual
216
+'
217
+
218
test_done