Skip to content

Commit be0d29d

Browse files
phillipwoodgitster
authored andcommitted
rebase --apply: make reflog messages match rebase --merge
The apply backend creates slightly different reflog messages to the merge backend when starting or finishing a rebase and when picking commits. These differences make it harder than it needs to be to parse the reflog (I have a script that reads the finishing messages from rebase and it is a pain to have to accommodate two different message formats). While it is possible to determine the backend used for a rebase from the reflog messages, the differences are not designed for that purpose. c2417d3 (rebase: drop '-i' from the reflog for interactive-based rebases, 2020-02-15) removed the clear distinction between the reflog messages of the two backends without complaint. As the merge backend is the default it is likely to be the format most common in existing reflogs. For that reason the apply backend is changed to format its reflog messages to match the merge backend as closely as possible. Note that there is still a difference as when committing a conflict resolution the apply backend will use "(pick)" rather than "(continue)" because it is not currently possible to change the message for a single commit. In addition to c2417d3 we also changed the reflog messages in 68aa495 (rebase: implement --merge via the interactive machinery, 2018-12-11) and 2ac0d62 (rebase: change the default backend from "am" to "merge", 2020-02-15). This commit makes the same change to "git rebase --apply" that 2ac0d62 made to "git rebase" without any backend specific options. As the messages are changed to use an existing format any scripts that can parse the reflog messages of the default rebase backend should be unaffected by this change. There are existing tests for the messages from both backends which are adjusted to ensure that they do not get out of sync in the future. Signed-off-by: Phillip Wood <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 33f2b61 commit be0d29d

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

builtin/rebase.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -582,10 +582,10 @@ static int move_to_original_branch(struct rebase_options *opts)
582582
if (!opts->onto)
583583
BUG("move_to_original_branch without onto");
584584

585-
strbuf_addf(&branch_reflog, "%s finished: %s onto %s",
585+
strbuf_addf(&branch_reflog, "%s (finish): %s onto %s",
586586
getenv(GIT_REFLOG_ACTION_ENVIRONMENT),
587587
opts->head_name, oid_to_hex(&opts->onto->object.oid));
588-
strbuf_addf(&head_reflog, "%s finished: returning to %s",
588+
strbuf_addf(&head_reflog, "%s (finish): returning to %s",
589589
getenv(GIT_REFLOG_ACTION_ENVIRONMENT), opts->head_name);
590590
ropts.branch = opts->head_name;
591591
ropts.flags = RESET_HEAD_REFS_ONLY;
@@ -615,7 +615,8 @@ static int run_am(struct rebase_options *opts)
615615

616616
am.git_cmd = 1;
617617
strvec_push(&am.args, "am");
618-
618+
strvec_pushf(&am.env, GIT_REFLOG_ACTION_ENVIRONMENT "=%s (pick)",
619+
getenv(GIT_REFLOG_ACTION_ENVIRONMENT));
619620
if (opts->action && !strcmp("continue", opts->action)) {
620621
strvec_push(&am.args, "--resolved");
621622
strvec_pushf(&am.args, "--resolvemsg=%s", resolvemsg);
@@ -1792,7 +1793,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
17921793
printf(_("First, rewinding head to replay your work on top of "
17931794
"it...\n"));
17941795

1795-
strbuf_addf(&msg, "%s: checkout %s",
1796+
strbuf_addf(&msg, "%s (start): checkout %s",
17961797
getenv(GIT_REFLOG_ACTION_ENVIRONMENT), options.onto_name);
17971798
ropts.oid = &options.onto->object.oid;
17981799
ropts.orig_head = &options.orig_head->object.oid,

t/t3406-rebase-message.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ test_expect_success 'error out early upon -C<n> or --whitespace=<bad>' '
8888
write_reflog_expect () {
8989
if test $mode = --apply
9090
then
91-
sed 's/(finish)/finished/; s/ ([^)]*)//'
91+
sed 's/(continue)/(pick)/'
9292
else
9393
cat
9494
fi >expect

0 commit comments

Comments
 (0)