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>
Johannes Schindelin committed
Jan 2, 2017 at 16:28 UTC
bcbb68be2e287209eb257de314d72d022712e4c9
1 file changed
+17
-8
sequencer.c
+17
-8
@@ -860,7 +860,7 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
860
const char *base_label, *next_label;
861
struct commit_message msg = { NULL, NULL, NULL, NULL };
862
struct strbuf msgbuf = STRBUF_INIT;
863
- int res, unborn = 0, amend = 0, allow;
863
+ int res, unborn = 0, amend = 0, allow = 0;
864
865
if (opts->no_commit) {
866
/*
@@ -905,11 +905,23 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
905
else
906
parent = commit->parents->item;
907
908
+ if (get_message(commit, &msg) != 0)
909
+ return error(_("cannot get commit message for %s"),
910
+ oid_to_hex(&commit->object.oid));
911
+
912
if (opts->allow_ff && !is_fixup(command) &&
913
((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
+ }
925
if (parent && parse_commit(parent) < 0)
926
/* TRANSLATORS: The first %s will be a "todo" command like
927
"revert" or "pick", the second %s a SHA1. */
@@ -917,10 +929,6 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
929
command_to_string(command),
930
oid_to_hex(&parent->object.oid));
931
920
- if (get_message(commit, &msg) != 0)
921
- return error(_("cannot get commit message for %s"),
922
- oid_to_hex(&commit->object.oid));
923
-
932
/*
933
* "commit" is an existing commit. We would want to apply
934
* 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,
1052
goto leave;
1053
}
1054
if (!opts->no_commit)
1055
+fast_forward_edit:
1056
res = run_git_commit(msg_file, opts, allow, edit, amend,
1057
cleanup_commit_message);
1058