Skip to content

Commit bcbb68b

Browse files
dschogitster
authored andcommitted
sequencer (rebase -i): allow fast-forwarding for edit/reword
The sequencer already knew how to fast-forward instead of cherry-picking, if possible. We want to continue to do this, of course, but in case of the 'reword' command, we will need to call `git commit` after fast-forwarding. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 04efc8b commit bcbb68b

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

sequencer.c

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,7 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
860860
const char *base_label, *next_label;
861861
struct commit_message msg = { NULL, NULL, NULL, NULL };
862862
struct strbuf msgbuf = STRBUF_INIT;
863-
int res, unborn = 0, amend = 0, allow;
863+
int res, unborn = 0, amend = 0, allow = 0;
864864

865865
if (opts->no_commit) {
866866
/*
@@ -905,22 +905,30 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
905905
else
906906
parent = commit->parents->item;
907907

908+
if (get_message(commit, &msg) != 0)
909+
return error(_("cannot get commit message for %s"),
910+
oid_to_hex(&commit->object.oid));
911+
908912
if (opts->allow_ff && !is_fixup(command) &&
909913
((parent && !hashcmp(parent->object.oid.hash, head)) ||
910-
(!parent && unborn)))
911-
return fast_forward_to(commit->object.oid.hash, head, unborn, opts);
912-
914+
(!parent && unborn))) {
915+
if (is_rebase_i(opts))
916+
write_author_script(msg.message);
917+
res = fast_forward_to(commit->object.oid.hash, head, unborn,
918+
opts);
919+
if (res || command != TODO_REWORD)
920+
goto leave;
921+
edit = amend = 1;
922+
msg_file = NULL;
923+
goto fast_forward_edit;
924+
}
913925
if (parent && parse_commit(parent) < 0)
914926
/* TRANSLATORS: The first %s will be a "todo" command like
915927
"revert" or "pick", the second %s a SHA1. */
916928
return error(_("%s: cannot parse parent commit %s"),
917929
command_to_string(command),
918930
oid_to_hex(&parent->object.oid));
919931

920-
if (get_message(commit, &msg) != 0)
921-
return error(_("cannot get commit message for %s"),
922-
oid_to_hex(&commit->object.oid));
923-
924932
/*
925933
* "commit" is an existing commit. We would want to apply
926934
* the difference it introduces since its first parent "prev"
@@ -1044,6 +1052,7 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
10441052
goto leave;
10451053
}
10461054
if (!opts->no_commit)
1055+
fast_forward_edit:
10471056
res = run_git_commit(msg_file, opts, allow, edit, amend,
10481057
cleanup_commit_message);
10491058

0 commit comments

Comments
 (0)