Skip to content

Commit 1f6965f

Browse files
newrengitster
authored andcommitted
sequencer: honor GIT_REFLOG_ACTION
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 274b9cc commit 1f6965f

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
@@ -3708,10 +3708,11 @@ static const char *reflog_message(struct replay_opts *opts,
37083708
{
37093709
va_list ap;
37103710
static struct strbuf buf = STRBUF_INIT;
3711+
char *reflog_action = getenv(GIT_REFLOG_ACTION);
37113712

37123713
va_start(ap, fmt);
37133714
strbuf_reset(&buf);
3714-
strbuf_addstr(&buf, action_name(opts));
3715+
strbuf_addstr(&buf, reflog_action ? reflog_action : action_name(opts));
37153716
if (sub_action)
37163717
strbuf_addf(&buf, " (%s)", sub_action);
37173718
if (fmt) {
@@ -3799,8 +3800,11 @@ static int pick_commits(struct repository *r,
37993800
struct replay_opts *opts)
38003801
{
38013802
int res = 0, reschedule = 0;
3803+
char *prev_reflog_action;
38023804

3805+
/* Note that 0 for 3rd parameter of setenv means set only if not set */
38033806
setenv(GIT_REFLOG_ACTION, action_name(opts), 0);
3807+
prev_reflog_action = xstrdup(getenv(GIT_REFLOG_ACTION));
38043808
if (opts->allow_ff)
38053809
assert(!(opts->signoff || opts->no_commit ||
38063810
opts->record_origin || opts->edit));
@@ -3845,12 +3849,14 @@ static int pick_commits(struct repository *r,
38453849
}
38463850
if (item->command <= TODO_SQUASH) {
38473851
if (is_rebase_i(opts))
3848-
setenv("GIT_REFLOG_ACTION", reflog_message(opts,
3852+
setenv(GIT_REFLOG_ACTION, reflog_message(opts,
38493853
command_to_string(item->command), NULL),
38503854
1);
38513855
res = do_pick_commit(r, item->command, item->commit,
38523856
opts, is_final_fixup(todo_list),
38533857
&check_todo);
3858+
if (is_rebase_i(opts))
3859+
setenv(GIT_REFLOG_ACTION, prev_reflog_action, 1);
38543860
if (is_rebase_i(opts) && res < 0) {
38553861
/* Reschedule */
38563862
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)