Skip to content

Commit 3aa30cc

Browse files
committed
Merge branch 'en/sequencer-reflog-action'
"git rebase -i" did not leave the reflog entries correctly. * en/sequencer-reflog-action: sequencer: honor GIT_REFLOG_ACTION
2 parents 3ea2b46 + 1f6965f commit 3aa30cc

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

sequencer.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3724,10 +3724,11 @@ static const char *reflog_message(struct replay_opts *opts,
37243724
{
37253725
va_list ap;
37263726
static struct strbuf buf = STRBUF_INIT;
3727+
char *reflog_action = getenv(GIT_REFLOG_ACTION);
37273728

37283729
va_start(ap, fmt);
37293730
strbuf_reset(&buf);
3730-
strbuf_addstr(&buf, action_name(opts));
3731+
strbuf_addstr(&buf, reflog_action ? reflog_action : action_name(opts));
37313732
if (sub_action)
37323733
strbuf_addf(&buf, " (%s)", sub_action);
37333734
if (fmt) {
@@ -3815,8 +3816,11 @@ static int pick_commits(struct repository *r,
38153816
struct replay_opts *opts)
38163817
{
38173818
int res = 0, reschedule = 0;
3819+
char *prev_reflog_action;
38183820

3821+
/* Note that 0 for 3rd parameter of setenv means set only if not set */
38193822
setenv(GIT_REFLOG_ACTION, action_name(opts), 0);
3823+
prev_reflog_action = xstrdup(getenv(GIT_REFLOG_ACTION));
38203824
if (opts->allow_ff)
38213825
assert(!(opts->signoff || opts->no_commit ||
38223826
opts->record_origin || opts->edit));
@@ -3861,12 +3865,14 @@ static int pick_commits(struct repository *r,
38613865
}
38623866
if (item->command <= TODO_SQUASH) {
38633867
if (is_rebase_i(opts))
3864-
setenv("GIT_REFLOG_ACTION", reflog_message(opts,
3868+
setenv(GIT_REFLOG_ACTION, reflog_message(opts,
38653869
command_to_string(item->command), NULL),
38663870
1);
38673871
res = do_pick_commit(r, item->command, item->commit,
38683872
opts, is_final_fixup(todo_list),
38693873
&check_todo);
3874+
if (is_rebase_i(opts))
3875+
setenv(GIT_REFLOG_ACTION, prev_reflog_action, 1);
38703876
if (is_rebase_i(opts) && res < 0) {
38713877
/* Reschedule */
38723878
advise(_(rescheduled_advice),

t/t3406-rebase-message.sh

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,22 +89,22 @@ test_expect_success 'GIT_REFLOG_ACTION' '
8989
git checkout -b reflog-topic start &&
9090
test_commit reflog-to-rebase &&
9191
92-
git rebase --apply reflog-onto &&
92+
git rebase reflog-onto &&
9393
git log -g --format=%gs -3 >actual &&
9494
cat >expect <<-\EOF &&
95-
rebase finished: returning to refs/heads/reflog-topic
96-
rebase: reflog-to-rebase
97-
rebase: checkout reflog-onto
95+
rebase (finish): returning to refs/heads/reflog-topic
96+
rebase (pick): reflog-to-rebase
97+
rebase (start): checkout reflog-onto
9898
EOF
9999
test_cmp expect actual &&
100100
101101
git checkout -b reflog-prefix reflog-to-rebase &&
102-
GIT_REFLOG_ACTION=change-the-reflog git rebase --apply reflog-onto &&
102+
GIT_REFLOG_ACTION=change-the-reflog git rebase reflog-onto &&
103103
git log -g --format=%gs -3 >actual &&
104104
cat >expect <<-\EOF &&
105-
rebase finished: returning to refs/heads/reflog-prefix
106-
change-the-reflog: reflog-to-rebase
107-
change-the-reflog: checkout reflog-onto
105+
change-the-reflog (finish): returning to refs/heads/reflog-prefix
106+
change-the-reflog (pick): reflog-to-rebase
107+
change-the-reflog (start): checkout reflog-onto
108108
EOF
109109
test_cmp expect actual
110110
'

0 commit comments

Comments
 (0)