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

[PATCH 09/18] t3404: Test the commit count in commit messages generated by "rebase -i"

From
Michael Haggerty <mhagger@alum.mit.edu>
Date
Jan 14, 2010, 05:54 UTC
Message-ID
<c3ec064944c4c5e6a3eba5c71e8956fe8bceb3ad.1263447037.git.mhagger@alum.mit.edu>
In-Reply-To
<cover.1263447037.git.mhagger@alum.mit.edu>

The first line of commit messages generated for "rebase -i" squash/fixup commits includes a count of the number of commits that are being combined. Add machinery to check that this count is correct, and add such a check to some test cases.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
---
 t/lib-rebase.sh               |    6 +++++-
 t/t3404-rebase-interactive.sh |    9 +++++++--
 2 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/t/lib-rebase.sh b/t/lib-rebase.sh
index 0db8250..2d922ae 100644
--- a/t/lib-rebase.sh
+++ b/t/lib-rebase.sh
@@ -2,9 +2,10 @@
 
 # After setting the fake editor with this function, you can
 #
-# - override the commit message with $FAKE_COMMIT_MESSAGE,
+# - override the commit message with $FAKE_COMMIT_MESSAGE
 # - amend the commit message with $FAKE_COMMIT_AMEND
 # - check that non-commit messages have a certain line count with $EXPECT_COUNT
+# - check the commit count in the commit message header with $EXPECT_HEADER_COUNT
 # - rewrite a rebase -i script as directed by $FAKE_LINES.
 #   $FAKE_LINES consists of a sequence of words separated by spaces.
 #   The following word combinations are possible:
@@ -25,6 +26,9 @@ set_fake_editor () {
 	cat >> fake-editor.sh <<\EOF
 case "$1" in
 */COMMIT_EDITMSG)
+	test -z "$EXPECT_HEADER_COUNT" ||
+		test "$EXPECT_HEADER_COUNT" = $(sed -n '1s/^# This is a combination of \(.*\) commits\./\1/p' < "$1") ||
+		exit
 	test -z "$FAKE_COMMIT_MESSAGE" || echo "$FAKE_COMMIT_MESSAGE" > "$1"
 	test -z "$FAKE_COMMIT_AMEND" || echo "$FAKE_COMMIT_AMEND" >> "$1"
 	exit
diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh
index d9382e4..0335b78 100755
--- a/t/t3404-rebase-interactive.sh
+++ b/t/t3404-rebase-interactive.sh
@@ -135,7 +135,8 @@ test_expect_success 'squash' '
 	test_tick &&
 	GIT_AUTHOR_NAME="Nitfol" git commit -m "nitfol" file7 &&
 	echo "******************************" &&
-	FAKE_LINES="1 squash 2" git rebase -i --onto master HEAD~2 &&
+	FAKE_LINES="1 squash 2" EXPECT_HEADER_COUNT=two \
+		git rebase -i --onto master HEAD~2 &&
 	test B = $(cat file7) &&
 	test $(git rev-parse HEAD^) = $(git rev-parse master)
 '
@@ -230,6 +231,7 @@ test_expect_success 'verbose flag is heeded, even after --continue' '
 test_expect_success 'multi-squash only fires up editor once' '
 	base=$(git rev-parse HEAD~4) &&
 	FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="1 squash 2 squash 3 squash 4" \
+		EXPECT_HEADER_COUNT=4 \
 		git rebase -i $base &&
 	test $base = $(git rev-parse HEAD^) &&
 	test 1 = $(git show | grep ONCE | wc -l)
@@ -239,6 +241,7 @@ test_expect_success 'multi-fixup only fires up editor once' '
 	git checkout -b multi-fixup E &&
 	base=$(git rev-parse HEAD~4) &&
 	FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="1 fixup 2 fixup 3 fixup 4" \
+		EXPECT_HEADER_COUNT=4 \
 		git rebase -i $base &&
 	test $base = $(git rev-parse HEAD^) &&
 	test 1 = $(git show | grep ONCE | wc -l) &&
@@ -258,6 +261,7 @@ test_expect_success 'squash and fixup generate correct log messages' '
 	git checkout -b squash-fixup E &&
 	base=$(git rev-parse HEAD~4) &&
 	FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="1 fixup 2 squash 3 fixup 4" \
+		EXPECT_HEADER_COUNT=4 \
 		git rebase -i $base &&
 	git cat-file commit HEAD | sed -e 1,/^\$/d > actual-squash-fixup &&
 	test_cmp expect-squash-fixup actual-squash-fixup &&
@@ -297,7 +301,8 @@ test_expect_success 'squash works as expected' '
 		git commit -m $n
 	done &&
 	one=$(git rev-parse HEAD~3) &&
-	FAKE_LINES="1 squash 3 2" git rebase -i HEAD~3 &&
+	FAKE_LINES="1 squash 3 2" EXPECT_HEADER_COUNT=two \
+		git rebase -i HEAD~3 &&
 	test $one = $(git rev-parse HEAD~2)
 '
 
-- 
1.6.6
Previous: Michael HaggertyNext: Johannes Sixt
Message 17 of 34 in “rebase -i: For pure fixups, do not start log message editor”
  1. 00/18 rebase -i: For pure fixups, do not start log message editorMichael Haggerty, Jan 14, 2010
  2. 01/18 rebase -i: Make the condition for an "if" more transparentMichael Haggerty, Jan 14, 2010
  3. Eric BlakeJan 14, 2010
  4. Junio C HamanoJan 14, 2010
  5. Paolo BonziniJan 15, 2010
  6. Johannes SchindelinJan 25, 2010
  7. Michael HaggertyJan 26, 2010
  8. Johannes SchindelinJan 26, 2010
  9. 02/18 rebase -i: Remove dead codeMichael Haggerty, Jan 14, 2010
  10. 03/18 rebase -i: Inline expressionMichael Haggerty, Jan 14, 2010
  11. 04/18 rebase -i: Use "test -n" instead of "test ! -z"Michael Haggerty, Jan 14, 2010
  12. 05/18 rebase -i: Use symbolic constant $MSG consistentlyMichael Haggerty, Jan 14, 2010
  13. 06/18 rebase -i: Document how temporary files are usedMichael Haggerty, Jan 14, 2010
  14. Greg PriceJan 25, 2010
  15. 07/18 rebase -i: Introduce a constant AUTHOR_SCRIPTMichael Haggerty, Jan 14, 2010
  16. 08/18 rebase -i: Introduce a constant AMENDMichael Haggerty, Jan 14, 2010
  17. 09/18 t3404: Test the commit count in commit messages generated by "rebase -i"Michael Haggerty, Jan 14, 2010
  18. Johannes SixtJan 14, 2010
  19. Michael HaggertyJan 14, 2010
  20. Johannes SixtJan 14, 2010
  21. 10/18 rebase -i: Improve consistency of commit count in generated commit messagesMichael Haggerty, Jan 14, 2010
  22. Johannes SixtJan 14, 2010
  23. Michael HaggertyJan 14, 2010
  24. 11/18 rebase -i: Simplify commit counting for generated commit messagesMichael Haggerty, Jan 14, 2010
  25. 12/18 rebase -i: Extract a function "commit_message"Michael Haggerty, Jan 14, 2010
  26. 13/18 rebase -i: Handle the author script all in one place in do_nextMichael Haggerty, Jan 14, 2010
  27. 14/18 rebase -i: Extract function do_with_authorMichael Haggerty, Jan 14, 2010
  28. 15/18 rebase -i: Change function make_squash_message into update_squash_messageMichael Haggerty, Jan 14, 2010
  29. Johannes SixtJan 14, 2010
  30. 16/18 rebase -i: For fixup commands without squashes, do not start editorMichael Haggerty, Jan 14, 2010
  31. 17/18 t3404: Set up more of the test repo in the "setup" stepMichael Haggerty, Jan 14, 2010
  32. 18/18 rebase -i: Retain user-edited commit messages after squash/fixup conflictsMichael Haggerty, Jan 14, 2010
  33. Junio C HamanoJan 14, 2010
  34. Johannes SchindelinJan 25, 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.