]> git.ipfire.org Git - thirdparty/git.git/commit
sequencer: avoid dropping fixup commit that targets self via commit-ish
authorJohannes Altmanninger <aclopte@gmail.com>
Sat, 24 Sep 2022 22:29:04 +0000 (17:29 -0500)
committerJunio C Hamano <gitster@pobox.com>
Mon, 26 Sep 2022 17:11:57 +0000 (10:11 -0700)
commit3e367a5f2f53f19130b90a97c3e2668eca3461ae
tree57463b455f8c942a070323ee3f3370863a019b9e
parentfd59c5bdeeb50f18e86f36cbf7a0b82554621690
sequencer: avoid dropping fixup commit that targets self via commit-ish

Commit 68d5d03bc4 (rebase: teach --autosquash to match on sha1 in
addition to message, 2010-11-04) taught autosquash to recognize
subjects like "fixup! 7a235b" where 7a235b is an OID-prefix. It
actually did more than advertised: 7a235b can be an arbitrary
commit-ish (as long as it's not trailed by spaces).

Accidental(?) use of this secret feature revealed a bug where we
would silently drop a fixup commit. The bug can also be triggered
when using an OID-prefix but that's unlikely in practice.

Let the commit with subject "fixup! main" be the tip of the "main"
branch. When computing the fixup target for this commit, we find
the commit itself. This is wrong because, by definition, a fixup
target must be an earlier commit in the todo list. We wrongly find
the current commit because we added it to the todo list prematurely.
Avoid these fixup-cycles by only adding the current commit to the
todo list after we have finished looking for the fixup target.

Reported-by: Erik Cervin Edin <erik@cervined.in>
Signed-off-by: Johannes Altmanninger <aclopte@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
sequencer.c
t/t3415-rebase-autosquash.sh