From: Shlok Kulshreshtha <diy2903@gmail.com>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>,
Shlok Kulshreshtha <diy2903@gmail.com>
Subject: [PATCH v2 1/2] test-lib-functions: add commit_body helper
Date: Mon, 27 Jul 2026 15:26:55 +0530 [thread overview]
Message-ID: <20260727095656.75496-2-diy2903@gmail.com> (raw)
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
next prev parent reply other threads:[~2026-07-27 9:57 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-26 22:48 [PATCH 0/2] t: add and use a commit_body test helper Shlok Kulshreshtha
2026-07-26 22:48 ` [PATCH 1/2] test-lib-functions: add commit_body helper Shlok Kulshreshtha
2026-07-26 22:48 ` [PATCH 2/2] t: use commit_body to extract commit message bodies Shlok Kulshreshtha
2026-07-27 8:15 ` [PATCH 0/2] t: add and use a commit_body test helper Junio C Hamano
2026-07-27 9:28 ` Shlok Kulshreshtha
2026-07-27 9:56 ` [PATCH v2 " Shlok Kulshreshtha
2026-07-27 9:56 ` Shlok Kulshreshtha [this message]
2026-07-27 9:56 ` [PATCH v2 2/2] t: use commit_body to extract commit message bodies Shlok Kulshreshtha
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260727095656.75496-2-diy2903@gmail.com \
--to=diy2903@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox