Skip to content

Commit da1d633

Browse files
phillipwoodgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4e5e1b4 commit da1d633

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

builtin/rebase.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,8 +1271,6 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
12711271
int fd;
12721272

12731273
options.action = "continue";
1274-
set_reflog_action(&options);
1275-
12761274
/* Sanity check */
12771275
if (get_oid("HEAD", &head))
12781276
die(_("Cannot read HEAD"));

sequencer.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4785,6 +4785,8 @@ int sequencer_continue(struct repository *r, struct replay_opts *opts)
47854785
if (read_populate_opts(opts))
47864786
return -1;
47874787
if (is_rebase_i(opts)) {
4788+
char *previous_reflog_action;
4789+
47884790
if ((res = read_populate_todo(r, &todo_list, opts)))
47894791
goto release_todo_list;
47904792

@@ -4795,10 +4797,13 @@ int sequencer_continue(struct repository *r, struct replay_opts *opts)
47954797
unlink(rebase_path_dropped());
47964798
}
47974799

4800+
previous_reflog_action = xstrdup(getenv(GIT_REFLOG_ACTION));
4801+
setenv(GIT_REFLOG_ACTION, reflog_message(opts, "continue", NULL), 1);
47984802
if (commit_staged_changes(r, opts, &todo_list)) {
47994803
res = -1;
48004804
goto release_todo_list;
48014805
}
4806+
setenv(GIT_REFLOG_ACTION, previous_reflog_action, 1);
48024807
} else if (!file_exists(get_todo_path(opts)))
48034808
return continue_single_pick(r, opts);
48044809
else if ((res = read_populate_todo(r, &todo_list, opts)))

t/t3406-rebase-message.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ test_expect_success 'setup' '
1717
1818
git checkout -b conflicts O &&
1919
test_commit P &&
20+
test_commit conflict-X fileX &&
2021
test_commit Q &&
2122
2223
git checkout -b topic O &&
@@ -107,13 +108,17 @@ test_reflog () {
107108
GIT_REFLOG_ACTION="$reflog_action" &&
108109
export GIT_REFLOG_ACTION
109110
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
111115
) &&
112116
113-
git log -g --format=%gs -4 >actual &&
117+
git log -g --format=%gs -5 >actual &&
114118
write_reflog_expect <<-EOF &&
115119
${reflog_action:-rebase} (finish): returning to refs/heads/conflicts
116120
${reflog_action:-rebase} (pick): Q
121+
${reflog_action:-rebase} (continue): conflict-X
117122
${reflog_action:-rebase} (pick): P
118123
${reflog_action:-rebase} (start): checkout main
119124
EOF

0 commit comments

Comments
 (0)