rebase --merge: fix reflog when continuing

The reflog message for a conflict resolution committed by "rebase --continue" looks like rebase (continue): commit subject line Unfortunately the reflog message each subsequent pick look like rebase (continue) (pick): commit subject line Fix this by setting the reflog message for "rebase --continue" in sequencer_continue() so it does not affect subsequent commits. This introduces a memory leak similar to the one leaking GIT_REFLOG_ACTION in pick_commits(). Both of these will be fixed in a future series that stops the sequencer calling setenv(). If we fail to commit the staged changes then we error out so GIT_REFLOG_ACTION does not need to be reset in that case. Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Phillip Wood committed Oct 12, 2022 at 09:35 UTC da1d63363f13d4d65c59564c74fd8dd598b39c49
3 files changed +12 -4
builtin/rebase.c
-2
@@ -1271,8 +1271,6 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1271 int fd;
1272
1273 options.action = "continue";
1274 - set_reflog_action(&options);
1275 -
1274 /* Sanity check */
1275 if (get_oid("HEAD", &head))
1276 die(_("Cannot read HEAD"));
sequencer.c
+5
@@ -4785,6 +4785,8 @@ int sequencer_continue(struct repository *r, struct replay_opts *opts)
4785 if (read_populate_opts(opts))
4786 return -1;
4787 if (is_rebase_i(opts)) {
4788 + char *previous_reflog_action;
4789 +
4790 if ((res = read_populate_todo(r, &todo_list, opts)))
4791 goto release_todo_list;
4792
@@ -4795,10 +4797,13 @@ int sequencer_continue(struct repository *r, struct replay_opts *opts)
4797 unlink(rebase_path_dropped());
4798 }
4799
4800 + previous_reflog_action = xstrdup(getenv(GIT_REFLOG_ACTION));
4801 + setenv(GIT_REFLOG_ACTION, reflog_message(opts, "continue", NULL), 1);
4802 if (commit_staged_changes(r, opts, &todo_list)) {
4803 res = -1;
4804 goto release_todo_list;
4805 }
4806 + setenv(GIT_REFLOG_ACTION, previous_reflog_action, 1);
4807 } else if (!file_exists(get_todo_path(opts)))
4808 return continue_single_pick(r, opts);
4809 else if ((res = read_populate_todo(r, &todo_list, opts)))
t/t3406-rebase-message.sh
+7 -2
@@ -17,6 +17,7 @@ test_expect_success 'setup' '
17
18 git checkout -b conflicts O &&
19 test_commit P &&
20 + test_commit conflict-X fileX &&
21 test_commit Q &&
22
23 git checkout -b topic O &&
@@ -107,13 +108,17 @@ test_reflog () {
108 GIT_REFLOG_ACTION="$reflog_action" &&
109 export GIT_REFLOG_ACTION
110 fi &&
110 - git rebase $mode main
111 + test_must_fail git rebase $mode main &&
112 + echo resolved >fileX &&
113 + git add fileX &&
114 + git rebase --continue
115 ) &&
116
113 - git log -g --format=%gs -4 >actual &&
117 + git log -g --format=%gs -5 >actual &&
118 write_reflog_expect <<-EOF &&
119 ${reflog_action:-rebase} (finish): returning to refs/heads/conflicts
120 ${reflog_action:-rebase} (pick): Q
121 + ${reflog_action:-rebase} (continue): conflict-X
122 ${reflog_action:-rebase} (pick): P
123 ${reflog_action:-rebase} (start): checkout main
124 EOF