In the upcoming patch to clean up fixup/squash commit messages even when skipping a final fixup/squash that failed with merge conflicts, we will need to have some indicator what happened. As we need to remove the message-fixup and message-squash files upon failure, we cannot use those. So let's just write an explicit amend-type file, containing either `fixup` or `squash`. The absence of that file indicates that the we were not in the middle of a fixup or squash when merge conflicts were happening. Signed-off-by: Johannes Schindelin <johannes.schindelin@xxxxxx> --- sequencer.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/sequencer.c b/sequencer.c index 667f35ebdff..a9c3bc26f84 100644 --- a/sequencer.c +++ b/sequencer.c @@ -106,6 +106,13 @@ static GIT_PATH_FUNC(rebase_path_author_script, "rebase-merge/author-script") * command is processed, this file is deleted. */ static GIT_PATH_FUNC(rebase_path_amend, "rebase-merge/amend") +/* + * If there was a merge conflict in a fixup/squash series, we need to + * record the type so that a `git rebase --skip` can clean up the commit + * message as appropriate. This file will contain that type (`fixup` or + * `squash`), and not exist otherwise. + */ +static GIT_PATH_FUNC(rebase_path_amend_type, "rebase-merge/amend-type") /* * When we stop at a given patch via the "edit" command, this file contains * the abbreviated commit name of the corresponding patch. @@ -2392,10 +2399,20 @@ static int error_with_patch(struct commit *commit, static int error_failed_squash(struct commit *commit, struct replay_opts *opts, int subject_len, const char *subject) { + const char *amend_type = "squash"; + + if (file_exists(rebase_path_fixup_msg())) { + unlink(rebase_path_fixup_msg()); + amend_type = "fixup"; + } + if (write_message(amend_type, strlen(amend_type), + rebase_path_amend_type(), 0)) + return error(_("could not write '%s'"), + rebase_path_amend_type()); + if (rename(rebase_path_squash_msg(), rebase_path_message())) return error(_("could not rename '%s' to '%s'"), rebase_path_squash_msg(), rebase_path_message()); - unlink(rebase_path_fixup_msg()); unlink(git_path_merge_msg()); if (copy_file(git_path_merge_msg(), rebase_path_message(), 0666)) return error(_("could not copy '%s' to '%s'"), @@ -2572,6 +2589,7 @@ static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts) unlink(rebase_path_author_script()); unlink(rebase_path_stopped_sha()); unlink(rebase_path_amend()); + unlink(rebase_path_amend_type()); delete_ref(NULL, "REBASE_HEAD", NULL, REF_NO_DEREF); } if (item->command <= TODO_SQUASH) { @@ -2799,6 +2817,7 @@ static int commit_staged_changes(struct replay_opts *opts) if (run_git_commit(rebase_path_message(), opts, flags)) return error(_("could not commit staged changes.")); unlink(rebase_path_amend()); + unlink(rebase_path_amend_type()); return 0; } -- 2.17.0.windows.1.15.gaa56ade3205