Skip to content

Commit d3d7a42

Browse files
lilyballgitster
authored andcommitted
rebase: better rearranging of fixup!/squash! lines with --autosquash
The current behvaior of --autosquash can duplicate fixup!/squash! lines if they match multiple commits, and it can also apply them to commits that come after them in the todo list. Even more oddly, a commit that looks like "fixup! fixup!" will match itself and be duplicated in the todo list. Change the todo list rearranging to mark all commits as used as soon as they are emitted, and to avoid emitting a fixup/squash commit if the commit has already been marked as used. Signed-off-by: Kevin Ballard <kevin@sb.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent af77aee commit d3d7a42

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

git-rebase--interactive.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,8 +687,12 @@ rearrange_squash () {
687687
*" $sha1 "*) continue ;;
688688
esac
689689
printf '%s\n' "$pick $sha1 $message"
690+
used="$used$sha1 "
690691
while read -r squash action msg
691692
do
693+
case " $used" in
694+
*" $squash "*) continue ;;
695+
esac
692696
case "$message" in
693697
"$msg"*)
694698
printf '%s\n' "$action $squash $action! $msg"

t/t3415-rebase-autosquash.sh

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,47 @@ test_expect_success 'misspelled auto squash' '
9494
test 0 = $(git rev-list final-missquash...HEAD | wc -l)
9595
'
9696

97+
test_expect_success 'auto squash that matches 2 commits' '
98+
git reset --hard base &&
99+
echo 4 >file4 &&
100+
git add file4 &&
101+
test_tick &&
102+
git commit -m "first new commit" &&
103+
echo 1 >file1 &&
104+
git add -u &&
105+
test_tick &&
106+
git commit -m "squash! first" &&
107+
git tag final-multisquash &&
108+
test_tick &&
109+
git rebase --autosquash -i HEAD~4 &&
110+
git log --oneline >actual &&
111+
test 4 = $(wc -l <actual) &&
112+
git diff --exit-code final-multisquash &&
113+
test 1 = "$(git cat-file blob HEAD^^:file1)" &&
114+
test 2 = $(git cat-file commit HEAD^^ | grep first | wc -l) &&
115+
test 1 = $(git cat-file commit HEAD | grep first | wc -l)
116+
'
117+
118+
test_expect_success 'auto squash that matches a commit after the squash' '
119+
git reset --hard base &&
120+
echo 1 >file1 &&
121+
git add -u &&
122+
test_tick &&
123+
git commit -m "squash! third" &&
124+
echo 4 >file4 &&
125+
git add file4 &&
126+
test_tick &&
127+
git commit -m "third commit" &&
128+
git tag final-presquash &&
129+
test_tick &&
130+
git rebase --autosquash -i HEAD~4 &&
131+
git log --oneline >actual &&
132+
test 5 = $(wc -l <actual) &&
133+
git diff --exit-code final-presquash &&
134+
test 0 = "$(git cat-file blob HEAD^^:file1)" &&
135+
test 1 = "$(git cat-file blob HEAD^:file1)" &&
136+
test 1 = $(git cat-file commit HEAD | grep third | wc -l) &&
137+
test 1 = $(git cat-file commit HEAD^ | grep third | wc -l)
138+
'
139+
97140
test_done

0 commit comments

Comments
 (0)