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

Re: [PATCH 0/3] Add a "fix" command to "rebase --interactive"

From
Junio C Hamano <gitster@pobox.com>
Date
Dec 9, 2009, 06:16 UTC
Message-ID
<7vaaxsvfie.fsf@alter.siamese.dyndns.org>
In-Reply-To
<7viqchhl7h.fsf@alter.siamese.dyndns.org>
Junio C Hamano <gitster@pobox.com> writes:
Show 32 quoted lines
> Nanako Shiraishi <nanako3@lavabit.com> writes:
>
>> @@ -519,6 +521,43 @@ get_saved_options () {
>>  	test -f "$DOTEST"/rebase-root && REBASE_ROOT=t
>>  }
>>  
>> +# Rearrange the todo list that has both "pick sha1 msg" and
>> +# "pick sha1 !fixup/!squash msg" appears in it so that the latter
>> +# comes immediately after the former, and change "pick" to
>> +# "fixup"/"squash".
>> +rearrange_squash () {
>> +	sed -n -e 's/^pick \([0-9a-f]*\) !\(squash\) /\1 \2 /p' \
>> +		-e 's/^pick \([0-9a-f]*\) !\(fixup\) /\1 \2 /p' \
>> +		"$1" >"$1.sq"
>> +	test -s "$1.sq" || return
>> +
>> +	sed -e '/^pick [0-9a-f]* !squash /d' \
>> +		-e '/^pick [0-9a-f]* !fixup /d' \
>> +		"$1" |
>> +	(
>> +		used=
>> +		while read pick sha1 message
>> +		do
>> +	...
>> +		done >"$1.rearranged"
>> +	)
>> +	cat "$1.rearranged" >"$1"
>> +	rm -f "$1.sq"
>> +}
>
> The logic to move the lines seem to have been improved since the last
> round, which is good.  I've amended this to remove "$1.rearranged" as well.

Actually I think the logic in the version from the June is more correct; doesn't this version drop commits that are marked as "squash! <message>" but with a misspelled <message> part? I think your old version, when it didn't find a matching one in early part, left such an unmatched "fixup" in place.

Here is a fix-up patch I think should be squashed in. I added a test to make sure that a mismatching "squash!" is kept in place. Please double check for sanity.

Thanks.
 git-rebase--interactive.sh   |   38 ++++++++++++++++----------------------
 t/t3415-rebase-autosquash.sh |   15 +++++++++++++++
 2 files changed, 31 insertions(+), 22 deletions(-)
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index c68cc5b..935e9e1 100755
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -531,29 +531,23 @@ rearrange_squash () {
 		"$1" >"$1.sq"
 	test -s "$1.sq" || return
 
-	sed -e '/^pick [0-9a-f]* squash! /d' \
-		-e '/^pick [0-9a-f]* fixup! /d' \
-		"$1" |
-	(
-		used=
-		while read pick sha1 message
+	used=
+	while read pick sha1 message
+	do
+		case " $used" in
+		*" $sha1 "*) continue ;;
+		esac
+		echo "$pick $sha1 $message"
+		while read squash action msg
 		do
-			echo "$pick $sha1 $message"
-			while read squash action msg
-			do
-				case " $used" in
-				*" $squash "*)
-					continue ;;
-				esac
-				case "$message" in
-				"$msg"*)
-					echo "$action $squash $action! $msg"
-					used="$used$squash "
-					;;
-				esac
-			done <"$1.sq"
-		done >"$1.rearranged"
-	)
+			case "$message" in
+			"$msg"*)
+				echo "$action $squash $action! $msg"
+				used="$used$squash "
+				;;
+			esac
+		done <"$1.sq"
+	done >"$1.rearranged" <"$1"
 	cat "$1.rearranged" >"$1"
 	rm -f "$1.sq" "$1.rearranged"
 }
diff --git a/t/t3415-rebase-autosquash.sh b/t/t3415-rebase-autosquash.sh
index f7a0f7a..b63f4e2 100755
--- a/t/t3415-rebase-autosquash.sh
+++ b/t/t3415-rebase-autosquash.sh
@@ -55,4 +55,19 @@ test_expect_success 'auto squash' '
 	test 2 = $(git cat-file commit HEAD^ | grep first | wc -l)
 '
 
+test_expect_success 'misspelled auto squash' '
+	git reset --hard base &&
+	echo 1 >file1 &&
+	git add -u &&
+	test_tick &&
+	git commit -m "squash! forst"
+	git tag final-missquash &&
+	test_tick &&
+	git rebase --autosquash -i HEAD^^^ &&
+	git log --oneline >actual &&
+	test 4 = $(wc -l <actual) &&
+	git diff --exit-code final-missquash &&
+	test 0 = $(git rev-list final-missquash...HEAD | wc -l)
+'
+
 test_done
Previous: Aaron CohenNext: Matthieu Moy
Message 28 of 32 in “Add a "fix" command to "rebase --interactive"”
  1. 0/3 Add a "fix" command to "rebase --interactive"Michael Haggerty, Dec 4, 2009
  2. 1/3 Better document the original repository layout.Michael Haggerty, Dec 4, 2009
  3. Michael J GruberDec 4, 2009
  4. Johannes SchindelinDec 4, 2009
  5. 2/3 Set a couple more tags in the original repository.Michael Haggerty, Dec 4, 2009
  6. Johannes SchindelinDec 4, 2009
  7. 3/3 Add a command "fix" to rebase --interactive.Michael Haggerty, Dec 4, 2009
  8. Johannes SchindelinDec 4, 2009
  9. Junio C HamanoDec 4, 2009
  10. Matthieu MoyDec 4, 2009
  11. Johannes SchindelinDec 4, 2009
  12. Junio C HamanoDec 5, 2009
  13. Michael J GruberDec 4, 2009
  14. Matthieu MoyDec 4, 2009
  15. Junio C HamanoDec 4, 2009
  16. Johannes SchindelinDec 4, 2009
  17. Nanako ShiraishiDec 4, 2009
  18. Junio C HamanoDec 5, 2009
  19. Nanako ShiraishiDec 8, 2009
  20. Junio C HamanoDec 8, 2009
  21. Nanako ShiraishiDec 8, 2009
  22. Junio C HamanoDec 8, 2009
  23. Junio C HamanoDec 8, 2009
  24. Jeff KingDec 8, 2009
  25. Sverre RabbelierDec 8, 2009
  26. Nanako ShiraishiDec 9, 2009
  27. Aaron CohenDec 9, 2009
  28. Junio C HamanoDec 9, 2009
  29. Matthieu MoyDec 8, 2009
  30. Shawn O. PearceDec 4, 2009
  31. Björn GustavssonDec 4, 2009
  32. Junio C HamanoDec 4, 2009

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.