Skip to content

Commit 7f8a6ca

Browse files
committed
Merge branch 'ja/rebase-i-avoid-amending-self' into maint-2.38
"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
2 parents cf96b39 + 3e367a5 commit 7f8a6ca

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

sequencer.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6203,8 +6203,6 @@ int todo_list_rearrange_squash(struct todo_list *todo_list)
62036203
return error(_("the script was already rearranged."));
62046204
}
62056205

6206-
*commit_todo_item_at(&commit_todo, item->commit) = item;
6207-
62086206
parse_commit(item->commit);
62096207
commit_buffer = logmsg_reencode(item->commit, NULL, "UTF-8");
62106208
find_commit_subject(commit_buffer, &subject);
@@ -6271,6 +6269,8 @@ int todo_list_rearrange_squash(struct todo_list *todo_list)
62716269
strhash(entry->subject));
62726270
hashmap_put(&subject2item, &entry->entry);
62736271
}
6272+
6273+
*commit_todo_item_at(&commit_todo, item->commit) = item;
62746274
}
62756275

62766276
if (rearranged) {

t/t3415-rebase-autosquash.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,19 @@ test_expect_success 'auto squash that matches longer sha1' '
232232
test_line_count = 1 actual
233233
'
234234

235+
test_expect_success 'auto squash of fixup commit that matches branch name which points back to fixup commit' '
236+
git reset --hard base &&
237+
git commit --allow-empty -m "fixup! self-cycle" &&
238+
git branch self-cycle &&
239+
GIT_SEQUENCE_EDITOR="cat >tmp" git rebase --autosquash -i HEAD^^ &&
240+
sed -ne "/^[^#]/{s/[0-9a-f]\{7,\}/HASH/g;p;}" tmp >actual &&
241+
cat <<-EOF >expect &&
242+
pick HASH second commit
243+
pick HASH fixup! self-cycle # empty
244+
EOF
245+
test_cmp expect actual
246+
'
247+
235248
test_auto_commit_flags () {
236249
git reset --hard base &&
237250
echo 1 >file1 &&

0 commit comments

Comments
 (0)