Skip to content

Commit 1d25c8c

Browse files
dschogitster
authored andcommitted
rebase -i: fix squashing corner case
When squashing, rebase -i did not prevent fast forwards. This could happen when picking some other commit than the first one, and then squashing the first commit. So do not allow fast forwards when squashing. Noticed by Johannes Sixt. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 191131e commit 1d25c8c

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

git-rebase--interactive.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,14 @@ die_abort () {
9696
}
9797

9898
pick_one () {
99-
case "$1" in -n) sha1=$2 ;; *) sha1=$1 ;; esac
99+
no_ff=
100+
case "$1" in -n) sha1=$2; no_ff=t ;; *) sha1=$1 ;; esac
100101
output git rev-parse --verify $sha1 || die "Invalid commit name: $sha1"
101102
test -d "$REWRITTEN" &&
102103
pick_one_preserving_merges "$@" && return
103104
parent_sha1=$(git rev-parse --verify $sha1^ 2>/dev/null)
104105
current_sha1=$(git rev-parse --verify HEAD)
105-
if test $current_sha1 = $parent_sha1; then
106+
if test $no_ff$current_sha1 = $parent_sha1; then
106107
output git reset --hard $sha1
107108
test "a$1" = a-n && output git reset --soft $current_sha1
108109
sha1=$(git rev-parse --short $sha1)

t/t3404-rebase-interactive.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,27 @@ test_expect_success 'interrupted squash works as expected' '
264264
test $one = $(git rev-parse HEAD~2)
265265
'
266266

267+
test_expect_success 'interrupted squash works as expected (case 2)' '
268+
for n in one two three four
269+
do
270+
echo $n >> conflict &&
271+
git add conflict &&
272+
git commit -m $n
273+
done &&
274+
one=$(git rev-parse HEAD~3) &&
275+
! FAKE_LINES="3 squash 1 2" git rebase -i HEAD~3 &&
276+
(echo one; echo four) > conflict &&
277+
git add conflict &&
278+
! git rebase --continue &&
279+
(echo one; echo two; echo four) > conflict &&
280+
git add conflict &&
281+
! git rebase --continue &&
282+
echo resolved > conflict &&
283+
git add conflict &&
284+
git rebase --continue &&
285+
test $one = $(git rev-parse HEAD~2)
286+
'
287+
267288
test_expect_success 'ignore patch if in upstream' '
268289
HEAD=$(git rev-parse HEAD) &&
269290
git checkout -b has-cherry-picked HEAD^ &&

0 commit comments

Comments
 (0)