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

[PATCHv3 1/2] rebase: better rearranging of fixup!/squash! lines with --autosquash

From
Kevin Ballard <kevin@sb.org>
Date
Nov 8, 2010, 10:48 UTC
Message-ID
<1289213283-24294-1-git-send-email-kevin@sb.org>
In-Reply-To
<alpine.DEB.2.00.1011051401090.7611@ds9.cixit.se>

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>
---
This patch is unchanged from v2.
 git-rebase--interactive.sh   |    4 +++
 t/t3415-rebase-autosquash.sh |   43 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 47 insertions(+), 0 deletions(-)
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index e29fd91..56cfdb5 100755
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -707,8 +707,12 @@ rearrange_squash () {
 		*" $sha1 "*) continue ;;
 		esac
 		printf '%s\n' "$pick $sha1 $message"
+		used="$used$sha1 "
 		while read -r squash action msg
 		do
+			case " $used" in
+			*" $squash "*) continue ;;
+			esac
 			case "$message" in
 			"$msg"*)
 				printf '%s\n' "$action $squash $action! $msg"
diff --git a/t/t3415-rebase-autosquash.sh b/t/t3415-rebase-autosquash.sh
index fd2184c..712bbe8 100755
--- a/t/t3415-rebase-autosquash.sh
+++ b/t/t3415-rebase-autosquash.sh
@@ -94,4 +94,47 @@ test_expect_success 'misspelled auto squash' '
 	test 0 = $(git rev-list final-missquash...HEAD | wc -l)
 '
 
+test_expect_success 'auto squash that matches 2 commits' '
+	git reset --hard base &&
+	echo 4 >file4 &&
+	git add file4 &&
+	test_tick &&
+	git commit -m "first new commit" &&
+	echo 1 >file1 &&
+	git add -u &&
+	test_tick &&
+	git commit -m "squash! first" &&
+	git tag final-multisquash &&
+	test_tick &&
+	git rebase --autosquash -i HEAD~4 &&
+	git log --oneline >actual &&
+	test 4 = $(wc -l <actual) &&
+	git diff --exit-code final-multisquash &&
+	test 1 = "$(git cat-file blob HEAD^^:file1)" &&
+	test 2 = $(git cat-file commit HEAD^^ | grep first | wc -l) &&
+	test 1 = $(git cat-file commit HEAD | grep first | wc -l)
+'
+
+test_expect_success 'auto squash that matches a commit after the squash' '
+	git reset --hard base &&
+	echo 1 >file1 &&
+	git add -u &&
+	test_tick &&
+	git commit -m "squash! third" &&
+	echo 4 >file4 &&
+	git add file4 &&
+	test_tick &&
+	git commit -m "third commit" &&
+	git tag final-presquash &&
+	test_tick &&
+	git rebase --autosquash -i HEAD~4 &&
+	git log --oneline >actual &&
+	test 5 = $(wc -l <actual) &&
+	git diff --exit-code final-presquash &&
+	test 0 = "$(git cat-file blob HEAD^^:file1)" &&
+	test 1 = "$(git cat-file blob HEAD^:file1)" &&
+	test 1 = $(git cat-file commit HEAD | grep third | wc -l) &&
+	test 1 = $(git cat-file commit HEAD^ | grep third | wc -l)
+'
+
 test_done
-- 
1.7.3.2.195.gc69dde
Previous: Peter KreftingNext: Yann Dirson
Message 10 of 13 in “rebase: better rearranging of fixup!/squash! lines with --autosquash”
  1. 1/2 rebase: better rearranging of fixup!/squash! lines with --autosquashKevin Ballard, Nov 4, 2010
  2. 2/2 rebase: teach --autosquash to match on sha1 in addition to messageKevin Ballard, Nov 4, 2010
  3. Kevin BallardNov 4, 2010
  4. Sverre RabbelierNov 4, 2010
  5. Kevin BallardNov 4, 2010
  6. Junio C HamanoNov 4, 2010
  7. 1/2 rebase: better rearranging of fixup!/squash! lines with --autosquashKevin Ballard, Nov 4, 2010
  8. 2/2 rebase: teach --autosquash to match on sha1 in addition to messageKevin Ballard, Nov 4, 2010
  9. Peter KreftingNov 5, 2010
  10. 1/2 rebase: better rearranging of fixup!/squash! lines with --autosquashKevin Ballard, Nov 8, 2010
  11. Yann DirsonNov 8, 2010
  12. Kevin BallardNov 8, 2010
  13. 2/2 rebase: teach --autosquash to match on sha1 in addition to messageKevin Ballard, Nov 8, 2010

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.