# bug in rebase--interactive with squash and conflicts

3 messages from 2007-08-21 to 2007-08-24. Participants: Johannes Sixt, Johannes Schindelin.
Thread: https://gitlist.dev/t/9597

## Johannes Sixt, 2007-08-21 15:10

Subject: bug in rebase--interactive with squash and conflicts
Message-ID: <46CB004C.AC39D562@eudaptics.com>
URL: https://gitlist.dev/e/46CB004C.AC39D562%40eudaptics.com

```
Hi,

There's a problem with rebase--interactive where I want to squash two
commits and the one to squash is the first in the original series. In
particular, I change the commit list from

	pick 1
	pick 2
	pick 3
to
	pick 3
	squash 1
	pick 2

In this case, the edits of commit 3 are lost. There are conflicts when
commits 3 and 1 are cherry-picked.

You can simulate the problematic case by applying this patch:

index 40d6799..861ece1 100755
--- a/t/t3404-rebase-interactive.sh
+++ b/t/t3404-rebase-interactive.sh
@@ -252,3 +252,4 @@ 'interrupted squash works as expected' '
 		echo $n >> conflict &&
-		git add conflict &&
+		echo $n > $n
+		git add conflict $n &&
 		git commit -m $n
@@ -256,3 +257,3 @@ 'interrupted squash works as expected' '
 	one=$(git rev-parse HEAD~3) &&
-	! FAKE_LINES="1 squash 3 2" git rebase -i HEAD~3 &&
+	! FAKE_LINES="3 squash 1 2" git rebase -i HEAD~3 &&
 	(echo one; echo two; echo four) > conflict &&


The test fails now, because git rebase --continue did not fail although
it should have. Run

   gitk HEAD to-be-rebased@{1}

Note that the rebase was completed, i.e. there are now 2 commits instead
of the original 3. But the file 'four' is missing and the final contents
of the file 'conflict' is

one
two
three

i.e. as if commit 3 had never taken place.

-- Hannes

```

## Johannes Schindelin, 2007-08-23 08:55

Subject: [PATCH] rebase -i: fix squashing corner case
Message-ID: <Pine.LNX.4.64.0708222334510.20400@racer.site>
URL: https://gitlist.dev/e/Pine.LNX.4.64.0708222334510.20400%40racer.site
In-Reply-To: <46CB004C.AC39D562@eudaptics.com>

```

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>
---

	On Tue, 21 Aug 2007, Johannes Sixt wrote:

	> There's a problem with rebase--interactive where I want to 
	> squash two commits and the one to squash is the first in the 
	> original series.

	Thanks.

 git-rebase--interactive.sh    |    5 +++--
 t/t3404-rebase-interactive.sh |   21 +++++++++++++++++++++
 2 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index bdec462..ec798a1 100755
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -96,13 +96,14 @@ die_abort () {
 }
 
 pick_one () {
-	case "$1" in -n) sha1=$2 ;; *) sha1=$1 ;; esac
+	no_ff=
+	case "$1" in -n) sha1=$2; no_ff=t ;; *) sha1=$1 ;; esac
 	output git rev-parse --verify $sha1 || die "Invalid commit name: $sha1"
 	test -d "$REWRITTEN" &&
 		pick_one_preserving_merges "$@" && return
 	parent_sha1=$(git rev-parse --verify $sha1^ 2>/dev/null)
 	current_sha1=$(git rev-parse --verify HEAD)
-	if test $current_sha1 = $parent_sha1; then
+	if test $no_ff$current_sha1 = $parent_sha1; then
 		output git reset --hard $sha1
 		test "a$1" = a-n && output git reset --soft $current_sha1
 		sha1=$(git rev-parse --short $sha1)
diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh
index 40d6799..718c9c1 100755
--- a/t/t3404-rebase-interactive.sh
+++ b/t/t3404-rebase-interactive.sh
@@ -264,6 +264,27 @@ test_expect_success 'interrupted squash works as expected' '
 	test $one = $(git rev-parse HEAD~2)
 '
 
+test_expect_success 'interrupted squash works as expected (case 2)' '
+	for n in one two three four
+	do
+		echo $n >> conflict &&
+		git add conflict &&
+		git commit -m $n
+	done &&
+	one=$(git rev-parse HEAD~3) &&
+	! FAKE_LINES="3 squash 1 2" git rebase -i HEAD~3 &&
+	(echo one; echo four) > conflict &&
+	git add conflict &&
+	! git rebase --continue &&
+	(echo one; echo two; echo four) > conflict &&
+	git add conflict &&
+	! git rebase --continue &&
+	echo resolved > conflict &&
+	git add conflict &&
+	git rebase --continue &&
+	test $one = $(git rev-parse HEAD~2)
+'
+
 test_expect_success 'ignore patch if in upstream' '
 	HEAD=$(git rev-parse HEAD) &&
 	git checkout -b has-cherry-picked HEAD^ &&
-- 
1.5.3.rc6.3.gaf460

```

## Johannes Sixt, 2007-08-24 07:18

Subject: Re: [PATCH] rebase -i: fix squashing corner case
Message-ID: <46CE8655.1DD79C48@eudaptics.com>
URL: https://gitlist.dev/e/46CE8655.1DD79C48%40eudaptics.com
In-Reply-To: <Pine.LNX.4.64.0708222334510.20400@racer.site>

```
Johannes Schindelin wrote:
> 
> 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.

This indeed fixes the problem. Hence:

Acked-by: Johannes Sixt <johannes.sixt@telecom.at>

Junio, please apply.

-- Hannes

```
