git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] rebase -i: fix interrupted squashing

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Jul 24, 2007, 20:43 UTC
Message-ID
<Pine.LNX.4.64.0707242139370.14781@racer.site>
In-Reply-To
<20070724200510.GA27610@informatik.uni-freiburg.de>

When a squashing merge failed, the first commit would not be replaced, due to "git reset --soft" being called with an unmerged index.

Noticed by Uwe Kleine-König.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
	On Tue, 24 Jul 2007, Uwe Kleine-K?nig wrote:
	> Johannes Schindelin wrote:
	>
	> > I'd appreciate if you prepared a patch with better 
	> > explanations, and also reviewed the man page, if it is in good 
	> > shape (and does not lie about the current behaviour).
	>
	> It's on my todo list, but not the top item for git.
	Please come around to do it.
	> In the mean-time I found another nuisance:
	> 
	> [outlines the test case provided in this patch]
	It would have been a bit less work for me, if you would have used 
	t/trash/ instead of /tmp/, and provided a patch for t3404 for me 
	to work with.
	Alas, the bug was squashed in 5 minutes.  It took me 15 minutes to 
	write (and test) the test.
	What a difference order can make...
 git-rebase--interactive.sh    |    2 +-
 t/t3404-rebase-interactive.sh |   30 ++++++++++++++++++++++++++++++
 2 files changed, 31 insertions(+), 1 deletions(-)
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index 93289c0..78ae51e 100755
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -258,8 +258,8 @@ do_next () {
 		esac
 
 		failed=f
-		pick_one -n $sha1 || failed=t
 		output git reset --soft HEAD^
+		pick_one -n $sha1 || failed=t
 		author_script=$(get_author_ident_from_commit $sha1)
 		echo "$author_script" > "$DOTEST"/author-script
 		case $failed in
diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh
index 8206436..817f614 100755
--- a/t/t3404-rebase-interactive.sh
+++ b/t/t3404-rebase-interactive.sh
@@ -221,4 +221,34 @@ test_expect_success 'multi-squash only fires up editor once' '
 	test 1 = $(git show | grep ONCE | wc -l)
 '
 
+test_expect_success 'squash works as expected' '
+	for n in one two three four
+	do
+		echo $n >> file$n &&
+		git add file$n &&
+		git commit -m $n
+	done &&
+	one=$(git rev-parse HEAD~3) &&
+	FAKE_LINES="1 squash 3 2" git rebase -i HEAD~3 &&
+	test $one = $(git rev-parse HEAD~2)
+'
+
+test_expect_success 'interrupted squash works as expected' '
+	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="1 squash 3 2" git rebase -i HEAD~3 &&
+	(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_done
-- 
1.5.3.rc2.42.gda8d
Previous: Uwe Kleine-KönigNext: Johannes Schindelin
Message 4 of 7 in “when git-rebase -i fails to cherry-pick”
  1. Uwe Kleine-KönigJul 23, 2007
  2. Johannes SchindelinJul 23, 2007
  3. Uwe Kleine-KönigJul 24, 2007
  4. rebase -i: fix interrupted squashingJohannes Schindelin, Jul 24, 2007
  5. Johannes SchindelinJul 27, 2007
  6. Junio C HamanoJul 27, 2007
  7. Johannes SchindelinJul 27, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.