Merge branch 'js/rebase-i-autosquash-fix'
authorJunio C Hamano <gitster@pobox.com>
Mon, 24 Sep 2018 17:30:45 +0000 (10:30 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 24 Sep 2018 17:30:45 +0000 (10:30 -0700)
"git rebase -i" did not clear the state files correctly when a run
of "squash/fixup" is aborted and then the user manually amended the
commit instead, which has been corrected.

* js/rebase-i-autosquash-fix:
rebase -i: be careful to wrap up fixup/squash chains
rebase -i --autosquash: demonstrate a problem skipping the last squash

1  2 
sequencer.c
diff --cc sequencer.c
index 00cefd129e4a9be73f3003186c90de439ba7d988,cccec6b70cc464c1fbeea6cb3f2f9aa82f96f8f8..0b14e200128165be78d959f4737d91b8368b1212
@@@ -3611,9 -3438,20 +3611,20 @@@ static int commit_staged_changes(struc
                 * the commit message and if there was a squash, let the user
                 * edit it.
                 */
-               if (is_clean && oideq(&head, &to_amend) &&
-                   opts->current_fixup_count > 0 &&
-                   file_exists(rebase_path_stopped_sha())) {
+               if (!is_clean || !opts->current_fixup_count)
+                       ; /* this is not the final fixup */
 -              else if (oidcmp(&head, &to_amend) ||
++              else if (!oideq(&head, &to_amend) ||
+                        !file_exists(rebase_path_stopped_sha())) {
+                       /* was a final fixup or squash done manually? */
+                       if (!is_fixup(peek_command(todo_list, 0))) {
+                               unlink(rebase_path_fixup_msg());
+                               unlink(rebase_path_squash_msg());
+                               unlink(rebase_path_current_fixups());
+                               strbuf_reset(&opts->current_fixups);
+                               opts->current_fixup_count = 0;
+                       }
+               } else {
+                       /* we are in a fixup/squash chain */
                        const char *p = opts->current_fixups.buf;
                        int len = opts->current_fixups.len;