]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'ja/rebase-i-avoid-amending-self' into maint-2.38
authorJunio C Hamano <gitster@pobox.com>
Wed, 26 Oct 2022 00:11:34 +0000 (17:11 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 26 Oct 2022 00:11:34 +0000 (17:11 -0700)
"git rebase -i" can mistakenly attempt to apply a fixup to a commit
itself, which has been corrected.

* ja/rebase-i-avoid-amending-self:
  sequencer: avoid dropping fixup commit that targets self via commit-ish

sequencer.c
t/t3415-rebase-autosquash.sh

index d26ede83c4b2beb1f14ee368bfc30958c4db6d07..a4d85f1fbdd4cbd12f590a1b400cb9939c903da0 100644 (file)
@@ -6203,8 +6203,6 @@ int todo_list_rearrange_squash(struct todo_list *todo_list)
                        return error(_("the script was already rearranged."));
                }
 
-               *commit_todo_item_at(&commit_todo, item->commit) = item;
-
                parse_commit(item->commit);
                commit_buffer = logmsg_reencode(item->commit, NULL, "UTF-8");
                find_commit_subject(commit_buffer, &subject);
@@ -6271,6 +6269,8 @@ int todo_list_rearrange_squash(struct todo_list *todo_list)
                                        strhash(entry->subject));
                        hashmap_put(&subject2item, &entry->entry);
                }
+
+               *commit_todo_item_at(&commit_todo, item->commit) = item;
        }
 
        if (rearranged) {
index 78c27496d6a715414e3a531ffe37fd790d5833c8..a364530d7629fc0bb47c30211935b878e1aa9805 100755 (executable)
@@ -232,6 +232,19 @@ test_expect_success 'auto squash that matches longer sha1' '
        test_line_count = 1 actual
 '
 
+test_expect_success 'auto squash of fixup commit that matches branch name which points back to fixup commit' '
+       git reset --hard base &&
+       git commit --allow-empty -m "fixup! self-cycle" &&
+       git branch self-cycle &&
+       GIT_SEQUENCE_EDITOR="cat >tmp" git rebase --autosquash -i HEAD^^ &&
+       sed -ne "/^[^#]/{s/[0-9a-f]\{7,\}/HASH/g;p;}" tmp >actual &&
+       cat <<-EOF >expect &&
+       pick HASH second commit
+       pick HASH fixup! self-cycle # empty
+       EOF
+       test_cmp expect actual
+'
+
 test_auto_commit_flags () {
        git reset --hard base &&
        echo 1 >file1 &&