Skip to content

Commit 13a5a9f

Browse files
dschogitster
authored andcommitted
rebase: fix GIT_REFLOG_ACTION regression
The scripted version of "rebase" honored the `GIT_REFLOG_ACTION`, and some automation scripts expected the reflog entries to be prefixed with "rebase -i", not "rebase", after running "rebase -i". This regressed in the reimplementation in C. Fix that, and add a regression test, both with `GIT_REFLOG_ACTION` set and unset. Note: the reflog message for "rebase finished" did *not* honor GIT_REFLOG_ACTION, and as we are very late in the v2.20.0-rcN phase, we leave that bug for later (as it seems that that bug has been with us from the very beginning). Reported by Ian Jackson. Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7068cbc commit 13a5a9f

File tree

2 files changed

+52
-3
lines changed

2 files changed

+52
-3
lines changed

builtin/rebase.c

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,23 @@ static void NORETURN error_on_missing_default_upstream(void)
776776
exit(1);
777777
}
778778

779+
static void set_reflog_action(struct rebase_options *options)
780+
{
781+
const char *env;
782+
struct strbuf buf = STRBUF_INIT;
783+
784+
if (!is_interactive(options))
785+
return;
786+
787+
env = getenv(GIT_REFLOG_ACTION_ENVIRONMENT);
788+
if (env && strcmp("rebase", env))
789+
return; /* only override it if it is "rebase" */
790+
791+
strbuf_addf(&buf, "rebase -i (%s)", options->action);
792+
setenv(GIT_REFLOG_ACTION_ENVIRONMENT, buf.buf, 1);
793+
strbuf_release(&buf);
794+
}
795+
779796
int cmd_rebase(int argc, const char **argv, const char *prefix)
780797
{
781798
struct rebase_options options = {
@@ -978,6 +995,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
978995

979996
if (action != NO_ACTION && !in_progress)
980997
die(_("No rebase in progress?"));
998+
setenv(GIT_REFLOG_ACTION_ENVIRONMENT, "rebase", 0);
981999

9821000
if (action == ACTION_EDIT_TODO && !is_interactive(&options))
9831001
die(_("The --edit-todo action can only be used during "
@@ -990,6 +1008,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
9901008
int fd;
9911009

9921010
options.action = "continue";
1011+
set_reflog_action(&options);
9931012

9941013
/* Sanity check */
9951014
if (get_oid("HEAD", &head))
@@ -1018,6 +1037,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
10181037
struct string_list merge_rr = STRING_LIST_INIT_DUP;
10191038

10201039
options.action = "skip";
1040+
set_reflog_action(&options);
10211041

10221042
rerere_clear(&merge_rr);
10231043
string_list_clear(&merge_rr, 1);
@@ -1033,6 +1053,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
10331053
case ACTION_ABORT: {
10341054
struct string_list merge_rr = STRING_LIST_INIT_DUP;
10351055
options.action = "abort";
1056+
set_reflog_action(&options);
10361057

10371058
rerere_clear(&merge_rr);
10381059
string_list_clear(&merge_rr, 1);
@@ -1440,11 +1461,12 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
14401461
}
14411462

14421463
strbuf_reset(&buf);
1443-
strbuf_addf(&buf, "rebase: checkout %s",
1464+
strbuf_addf(&buf, "%s: checkout %s",
1465+
getenv(GIT_REFLOG_ACTION_ENVIRONMENT),
14441466
options.switch_to);
14451467
if (reset_head(&oid, "checkout",
14461468
options.head_name, 0,
1447-
NULL, NULL) < 0) {
1469+
NULL, buf.buf) < 0) {
14481470
ret = !!error(_("could not switch to "
14491471
"%s"),
14501472
options.switch_to);
@@ -1508,7 +1530,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
15081530
printf(_("First, rewinding head to replay your work on top of "
15091531
"it...\n"));
15101532

1511-
strbuf_addf(&msg, "rebase: checkout %s", options.onto_name);
1533+
strbuf_addf(&msg, "%s: checkout %s",
1534+
getenv(GIT_REFLOG_ACTION_ENVIRONMENT), options.onto_name);
15121535
if (reset_head(&options.onto->object.oid, "checkout", NULL,
15131536
RESET_HEAD_DETACH, NULL, msg.buf))
15141537
die(_("Could not detach HEAD"));

t/t3406-rebase-message.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,30 @@ test_expect_success 'error out early upon -C<n> or --whitespace=<bad>' '
9191
test_i18ngrep "Invalid whitespace option" err
9292
'
9393

94+
test_expect_success 'GIT_REFLOG_ACTION' '
95+
git checkout start &&
96+
test_commit reflog-onto &&
97+
git checkout -b reflog-topic start &&
98+
test_commit reflog-to-rebase &&
99+
100+
git rebase reflog-onto &&
101+
git log -g --format=%gs -3 >actual &&
102+
cat >expect <<-\EOF &&
103+
rebase finished: returning to refs/heads/reflog-topic
104+
rebase: reflog-to-rebase
105+
rebase: checkout reflog-onto
106+
EOF
107+
test_cmp expect actual &&
108+
109+
git checkout -b reflog-prefix reflog-to-rebase &&
110+
GIT_REFLOG_ACTION=change-the-reflog git rebase reflog-onto &&
111+
git log -g --format=%gs -3 >actual &&
112+
cat >expect <<-\EOF &&
113+
rebase finished: returning to refs/heads/reflog-prefix
114+
change-the-reflog: reflog-to-rebase
115+
change-the-reflog: checkout reflog-onto
116+
EOF
117+
test_cmp expect actual
118+
'
119+
94120
test_done

0 commit comments

Comments
 (0)