Skip to content

Commit 6159e7a

Browse files
phillipwoodgitster
authored andcommitted
rebase --abort: improve reflog message
When aborting a rebase the reflog message looks like rebase (abort): updating HEAD which is not very informative. Improve the message by mentioning the branch that we are returning to as we do at the end of a successful rebase so it looks like. rebase (abort): returning to refs/heads/topic If GIT_REFLOG_ACTION is set in the environment we no longer omit "(abort)" from the reflog message. We don't omit "(start)" and "(finish)" when starting and finishing a rebase in that case so we shouldn't omit "(abort)". Signed-off-by: Phillip Wood <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent be0d29d commit 6159e7a

File tree

2 files changed

+59
-20
lines changed

2 files changed

+59
-20
lines changed

builtin/rebase.c

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,23 +1001,6 @@ static void NORETURN error_on_missing_default_upstream(void)
10011001
exit(1);
10021002
}
10031003

1004-
static void set_reflog_action(struct rebase_options *options)
1005-
{
1006-
const char *env;
1007-
struct strbuf buf = STRBUF_INIT;
1008-
1009-
if (!is_merge(options))
1010-
return;
1011-
1012-
env = getenv(GIT_REFLOG_ACTION_ENVIRONMENT);
1013-
if (env && strcmp("rebase", env))
1014-
return; /* only override it if it is "rebase" */
1015-
1016-
strbuf_addf(&buf, "rebase (%s)", options->action);
1017-
setenv(GIT_REFLOG_ACTION_ENVIRONMENT, buf.buf, 1);
1018-
strbuf_release(&buf);
1019-
}
1020-
10211004
static int check_exec_cmd(const char *cmd)
10221005
{
10231006
if (strchr(cmd, '\n'))
@@ -1311,18 +1294,23 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
13111294
}
13121295
case ACTION_ABORT: {
13131296
struct string_list merge_rr = STRING_LIST_INIT_DUP;
1314-
options.action = "abort";
1315-
set_reflog_action(&options);
1297+
struct strbuf head_msg = STRBUF_INIT;
13161298

1299+
options.action = "abort";
13171300
rerere_clear(the_repository, &merge_rr);
13181301
string_list_clear(&merge_rr, 1);
13191302

13201303
if (read_basic_state(&options))
13211304
exit(1);
1305+
1306+
strbuf_addf(&head_msg, "%s (abort): returning to %s",
1307+
getenv(GIT_REFLOG_ACTION_ENVIRONMENT),
1308+
options.head_name ? options.head_name
1309+
: oid_to_hex(&options.orig_head->object.oid));
13221310
ropts.oid = &options.orig_head->object.oid;
1311+
ropts.head_msg = head_msg.buf;
13231312
ropts.branch = options.head_name;
13241313
ropts.flags = RESET_HEAD_HARD;
1325-
ropts.default_reflog_action = DEFAULT_REFLOG_ACTION;
13261314
if (reset_head(the_repository, &ropts) < 0)
13271315
die(_("could not move back to %s"),
13281316
oid_to_hex(&options.orig_head->object.oid));

t/t3406-rebase-message.sh

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,57 @@ test_reflog () {
187187
EOF
188188
test_cmp expect actual
189189
'
190+
191+
test_expect_success "rebase $mode --abort reflog${reflog_action:+ GIT_REFLOG_ACTION=$reflog_action}" '
192+
git checkout conflicts &&
193+
test_when_finished "git reset --hard Q" &&
194+
195+
git log -g -1 conflicts >branch-expect &&
196+
(
197+
if test -n "$reflog_action"
198+
then
199+
GIT_REFLOG_ACTION="$reflog_action" &&
200+
export GIT_REFLOG_ACTION
201+
fi &&
202+
test_must_fail git rebase $mode main &&
203+
git rebase --abort
204+
) &&
205+
206+
git log -g --format=%gs -3 >actual &&
207+
write_reflog_expect <<-EOF &&
208+
${reflog_action:-rebase} (abort): returning to refs/heads/conflicts
209+
${reflog_action:-rebase} (pick): P
210+
${reflog_action:-rebase} (start): checkout main
211+
EOF
212+
test_cmp expect actual &&
213+
214+
# check branch reflog is unchanged
215+
git log -g -1 conflicts >branch-actual &&
216+
test_cmp branch-expect branch-actual
217+
'
218+
219+
test_expect_success "rebase $mode --abort detached HEAD reflog${reflog_action:+ GIT_REFLOG_ACTION=$reflog_action}" '
220+
git checkout Q &&
221+
test_when_finished "git reset --hard Q" &&
222+
223+
(
224+
if test -n "$reflog_action"
225+
then
226+
GIT_REFLOG_ACTION="$reflog_action" &&
227+
export GIT_REFLOG_ACTION
228+
fi &&
229+
test_must_fail git rebase $mode main &&
230+
git rebase --abort
231+
) &&
232+
233+
git log -g --format=%gs -3 >actual &&
234+
write_reflog_expect <<-EOF &&
235+
${reflog_action:-rebase} (abort): returning to $(git rev-parse Q)
236+
${reflog_action:-rebase} (pick): P
237+
${reflog_action:-rebase} (start): checkout main
238+
EOF
239+
test_cmp expect actual
240+
'
190241
}
191242

192243
test_reflog --merge

0 commit comments

Comments
 (0)