strstr(ctx->current_fixups.buf, "\nsquash");
}
+/* Does the current fixup chain contain a "fixup -c" command? */
+static int seen_fixup_edit_msg(struct replay_ctx *ctx)
+{
+ return starts_with(ctx->current_fixups.buf, "fixup -c") ||
+ strstr(ctx->current_fixups.buf, "\nfixup -c");
+}
+
static void update_comment_bufs(struct strbuf *buf1, struct strbuf *buf2, int n)
{
strbuf_setlen(buf1, strlen(comment_line_str) + 1);
strbuf_release(&buf);
if (!res) {
- strbuf_addf(&ctx->current_fixups, "%s%s %s",
+ const char *fixup_flag = "";
+
+ if (is_fixup_flag(command, flag) && (flag & TODO_EDIT_FIXUP_MSG))
+ fixup_flag = " -c";
+
+ strbuf_addf(&ctx->current_fixups, "%s%s%s %s",
ctx->current_fixups.len ? "\n" : "",
- command_to_string(command),
+ command_to_string(command), fixup_flag,
oid_to_hex(&commit->object.oid));
res = write_message(ctx->current_fixups.buf,
ctx->current_fixups.len,
* message, no need to bother the user with
* opening the commit message in the editor.
*/
- if (!starts_with(p, "squash ") &&
- !strstr(p, "\nsquash "))
+ if (!seen_squash(ctx) &&
+ !seen_fixup_edit_msg(ctx))
flags = (flags & ~EDIT_MSG) | CLEANUP_MSG;
} else if (is_fixup(peek_command(todo_list, 0))) {
/*
test_commit_message HEAD expected-message
'
+test_expect_success 'fixup -c is remembered after skipping final fixup' '
+ test_when_finished "test_might_fail git rebase --abort" &&
+ cat >todo <<-\EOF &&
+ pick B
+ fixup -c A1
+ fixup A3
+ EOF
+ (
+ set_fake_editor &&
+ set_replace_editor todo &&
+ test_must_fail git rebase -i A A &&
+ git show && cat .git/rebase-merge/message-squash &&
+ FAKE_COMMIT_AMEND=edited git rebase --skip
+ ) &&
+ test_commit_message HEAD <<-\EOF
+ new subject
+
+ new
+ body
+
+ edited
+ EOF
+'
+test_expect_success 'fixup -c is remembered after skipping later fixup' '
+ test_when_finished "test_might_fail git rebase --abort" &&
+ cat >todo <<-\EOF &&
+ pick B
+ fixup -c A1
+ fixup A3
+ fixup A2
+ EOF
+ (
+ set_fake_editor &&
+ set_replace_editor todo &&
+ test_must_fail git rebase -i A A &&
+ FAKE_COMMIT_AMEND=edited git rebase --skip
+ ) &&
+ test_commit_message HEAD <<-\EOF
+ new subject
+
+ new
+ body
+
+ edited
+ EOF
+'
+
test_expect_success 'sequence squash, fixup & fixup -c gives combined message' '
test_when_finished "test_might_fail git rebase --abort" &&
git checkout --detach A3 &&