Skip to content

Commit 537e7d6

Browse files
dschogitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a9be29c commit 537e7d6

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

sequencer.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3074,7 +3074,10 @@ static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts)
30743074
item->arg, item->arg_len,
30753075
item->flags, opts)) < 0)
30763076
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)
30783081
/* failed with merge conflicts */
30793082
return error_with_patch(item->commit,
30803083
item->arg,

t/t3430-rebase-merges.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,4 +190,29 @@ test_expect_success 'refs/rewritten/* is worktree-local' '
190190
test_cmp_rev HEAD "$(cat wt/b)"
191191
'
192192

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+
193218
test_done

0 commit comments

Comments
 (0)