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

[PATCH v2 1/2] test-lib-functions: add commit_body helper

From
Shlok Kulshreshtha <diy2903@gmail.com>
Date
Jul 27, 2026, 09:56 UTC
Message-ID
<20260727095656.75496-2-diy2903@gmail.com>
In-Reply-To
<20260727095656.75496-1-diy2903@gmail.com>

Extracting the message body of a commit -- running "git cat-file commit" and stripping everything up to and including the first blank line with "sed" -- is spelled out in about 60 places across the test suite.

Add a helper for it, so that the operation is written once instead of being copied around.

The commit object goes to a temporary file rather than into a pipe, because a pipeline reports only its last command's exit status, so a failure of "git cat-file" would go unnoticed.

Signed-off-by: Shlok Kulshreshtha <diy2903@gmail.com>
---
 t/README                | 11 +++++++++++
 t/test-lib-functions.sh |  8 ++++++++
 2 files changed, 19 insertions(+)
diff --git a/t/README b/t/README
index 4252774f86..9a9daaf2af 100644
--- a/t/README
+++ b/t/README
@@ -945,6 +945,17 @@ see test-lib-functions.sh for the full list and their options.
    Merges the given rev using the given message.  Like test_commit,
    creates a tag and calls test_tick before committing.
 
+ - commit_body <rev>
+
+   Print the message body of <rev>, i.e. the contents of its commit
+   object with the header removed.  Use this instead of piping
+   "git cat-file commit" into "sed", which would hide a failure of
+   the git command.
+
+   Example:
+
+	commit_body HEAD >actual
+
  - test_set_prereq <prereq>
 
    Set a test prerequisite to be used later with test_have_prereq. The
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index 809c662124..03bf31d8ef 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -1433,6 +1433,14 @@ test_commit_message () {
 	test_cmp "$msg_file" actual.msg
 }
 
+# Print the message body of a commit
+# Usage: commit_body <rev>
+commit_body () {
+	git cat-file commit "$1" >.commit &&
+	sed -e "1,/^$/d" .commit &&
+	rm -f .commit
+}
+
 # Compare paths respecting core.ignoreCase
 test_cmp_fspath () {
 	if test "x$1" = "x$2"
-- 
2.52.0
Previous: Shlok KulshreshthaNext: Shlok Kulshreshtha
Message 7 of 11 in “t: add and use a commit_body test helper”
  1. 0/2 t: add and use a commit_body test helperShlok Kulshreshtha, Jul 26, 2026
  2. 1/2 test-lib-functions: add commit_body helperShlok Kulshreshtha, Jul 26, 2026
  3. 2/2 t: use commit_body to extract commit message bodiesShlok Kulshreshtha, Jul 26, 2026
  4. Junio C HamanoJul 27, 2026
  5. Shlok KulshreshthaJul 27, 2026
  6. 0/2 t: add and use a commit_body test helperShlok Kulshreshtha, Jul 27, 2026
  7. 1/2 test-lib-functions: add commit_body helperShlok Kulshreshtha, Jul 27, 2026
  8. 2/2 t: use commit_body to extract commit message bodiesShlok Kulshreshtha, Jul 27, 2026
  9. Junio C HamanoJul 29, 2026
  10. Shlok KulshreshthaJul 30, 2026
  11. Junio C HamanoJul 30, 2026

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.