]> git.ipfire.org Git - thirdparty/git.git/commitdiff
sequencer: honor GIT_REFLOG_ACTION
authorElijah Newren <newren@gmail.com>
Tue, 7 Apr 2020 16:59:23 +0000 (16:59 +0000)
committerJunio C Hamano <gitster@pobox.com>
Tue, 7 Apr 2020 22:10:11 +0000 (15:10 -0700)
There is a lot of code to honor GIT_REFLOG_ACTION throughout git,
including some in sequencer.c; unfortunately, reflog_message() and its
callers ignored it.  Instruct reflog_message() to check the existing
environment variable, and use it when present as an override to
action_name().

Also restructure pick_commits() to only temporarily modify
GIT_REFLOG_ACTION for a short duration and then restore the old value,
so that when we do this setting within a loop we do not keep adding "
(pick)" substrings and end up with a reflog message of the form
    rebase (pick) (pick) (pick) (finish): returning to refs/heads/master

Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
sequencer.c
t/t3406-rebase-message.sh

index e528225e787f4e26de604807efc798e8b967010e..24a62d5aa5d333cca90de0bf4bb804ed9e9ec043 100644 (file)
@@ -3708,10 +3708,11 @@ static const char *reflog_message(struct replay_opts *opts,
 {
        va_list ap;
        static struct strbuf buf = STRBUF_INIT;
+       char *reflog_action = getenv(GIT_REFLOG_ACTION);
 
        va_start(ap, fmt);
        strbuf_reset(&buf);
-       strbuf_addstr(&buf, action_name(opts));
+       strbuf_addstr(&buf, reflog_action ? reflog_action : action_name(opts));
        if (sub_action)
                strbuf_addf(&buf, " (%s)", sub_action);
        if (fmt) {
@@ -3799,8 +3800,11 @@ static int pick_commits(struct repository *r,
                        struct replay_opts *opts)
 {
        int res = 0, reschedule = 0;
+       char *prev_reflog_action;
 
+       /* Note that 0 for 3rd parameter of setenv means set only if not set */
        setenv(GIT_REFLOG_ACTION, action_name(opts), 0);
+       prev_reflog_action = xstrdup(getenv(GIT_REFLOG_ACTION));
        if (opts->allow_ff)
                assert(!(opts->signoff || opts->no_commit ||
                                opts->record_origin || opts->edit));
@@ -3845,12 +3849,14 @@ static int pick_commits(struct repository *r,
                }
                if (item->command <= TODO_SQUASH) {
                        if (is_rebase_i(opts))
-                               setenv("GIT_REFLOG_ACTION", reflog_message(opts,
+                               setenv(GIT_REFLOG_ACTION, reflog_message(opts,
                                        command_to_string(item->command), NULL),
                                        1);
                        res = do_pick_commit(r, item->command, item->commit,
                                             opts, is_final_fixup(todo_list),
                                             &check_todo);
+                       if (is_rebase_i(opts))
+                               setenv(GIT_REFLOG_ACTION, prev_reflog_action, 1);
                        if (is_rebase_i(opts) && res < 0) {
                                /* Reschedule */
                                advise(_(rescheduled_advice),
index 61b76f3301982d26b808044bde9ce928f663112e..927a4f4a4e4a2d1d79f3d12f77ae4918c4fd6cee 100755 (executable)
@@ -89,22 +89,22 @@ test_expect_success 'GIT_REFLOG_ACTION' '
        git checkout -b reflog-topic start &&
        test_commit reflog-to-rebase &&
 
-       git rebase --apply reflog-onto &&
+       git rebase reflog-onto &&
        git log -g --format=%gs -3 >actual &&
        cat >expect <<-\EOF &&
-       rebase finished: returning to refs/heads/reflog-topic
-       rebase: reflog-to-rebase
-       rebase: checkout reflog-onto
+       rebase (finish): returning to refs/heads/reflog-topic
+       rebase (pick): reflog-to-rebase
+       rebase (start): checkout reflog-onto
        EOF
        test_cmp expect actual &&
 
        git checkout -b reflog-prefix reflog-to-rebase &&
-       GIT_REFLOG_ACTION=change-the-reflog git rebase --apply reflog-onto &&
+       GIT_REFLOG_ACTION=change-the-reflog git rebase reflog-onto &&
        git log -g --format=%gs -3 >actual &&
        cat >expect <<-\EOF &&
-       rebase finished: returning to refs/heads/reflog-prefix
-       change-the-reflog: reflog-to-rebase
-       change-the-reflog: checkout reflog-onto
+       change-the-reflog (finish): returning to refs/heads/reflog-prefix
+       change-the-reflog (pick): reflog-to-rebase
+       change-the-reflog (start): checkout reflog-onto
        EOF
        test_cmp expect actual
 '