]> git.ipfire.org Git - thirdparty/git.git/commitdiff
rebase --merge: fix reflog when continuing
authorPhillip Wood <phillip.wood@dunelm.org.uk>
Wed, 12 Oct 2022 09:35:07 +0000 (09:35 +0000)
committerJunio C Hamano <gitster@pobox.com>
Mon, 17 Oct 2022 19:55:03 +0000 (12:55 -0700)
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>
builtin/rebase.c
sequencer.c
t/t3406-rebase-message.sh

index e67020b3586446a7fcfde0f1bc425c93667f32b3..414526f83a898e59d71903d553ce1aa262369faf 100644 (file)
@@ -1271,8 +1271,6 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
                int fd;
 
                options.action = "continue";
-               set_reflog_action(&options);
-
                /* Sanity check */
                if (get_oid("HEAD", &head))
                        die(_("Cannot read HEAD"));
index 61a8e0020d596de550127d5b66f076034636239c..5790b35d763d0f97ffc37625232211215a535c78 100644 (file)
@@ -4785,6 +4785,8 @@ int sequencer_continue(struct repository *r, struct replay_opts *opts)
        if (read_populate_opts(opts))
                return -1;
        if (is_rebase_i(opts)) {
+               char *previous_reflog_action;
+
                if ((res = read_populate_todo(r, &todo_list, opts)))
                        goto release_todo_list;
 
@@ -4795,10 +4797,13 @@ int sequencer_continue(struct repository *r, struct replay_opts *opts)
                        unlink(rebase_path_dropped());
                }
 
+               previous_reflog_action = xstrdup(getenv(GIT_REFLOG_ACTION));
+               setenv(GIT_REFLOG_ACTION, reflog_message(opts, "continue", NULL), 1);
                if (commit_staged_changes(r, opts, &todo_list)) {
                        res = -1;
                        goto release_todo_list;
                }
+               setenv(GIT_REFLOG_ACTION, previous_reflog_action, 1);
        } else if (!file_exists(get_todo_path(opts)))
                return continue_single_pick(r, opts);
        else if ((res = read_populate_todo(r, &todo_list, opts)))
index 5253dd1551d018049beda5bac901560834b8375e..3ca2fbb0d59b870a55777e57075ac517aa43f41c 100755 (executable)
@@ -17,6 +17,7 @@ test_expect_success 'setup' '
 
        git checkout -b conflicts O &&
        test_commit P &&
+       test_commit conflict-X fileX &&
        test_commit Q &&
 
        git checkout -b topic O &&
@@ -107,13 +108,17 @@ test_reflog () {
                        GIT_REFLOG_ACTION="$reflog_action" &&
                        export GIT_REFLOG_ACTION
                fi &&
-               git rebase $mode main
+               test_must_fail git rebase $mode main &&
+               echo resolved >fileX &&
+               git add fileX &&
+               git rebase --continue
        ) &&
 
-       git log -g --format=%gs -4 >actual &&
+       git log -g --format=%gs -5 >actual &&
        write_reflog_expect <<-EOF &&
        ${reflog_action:-rebase} (finish): returning to refs/heads/conflicts
        ${reflog_action:-rebase} (pick): Q
+       ${reflog_action:-rebase} (continue): conflict-X
        ${reflog_action:-rebase} (pick): P
        ${reflog_action:-rebase} (start): checkout main
        EOF