t: use commit_body to extract commit message bodies
Replace the "git cat-file commit | sed" idiom with commit_body across the
test suite: 61 sites in 12 files, plus one local helper that wrapped the
same idiom. The idiom appears in four equivalent spellings -- piped or
written to a file first, "sed -e" or plain "sed", "\$" or "$" in the
address -- all producing byte-identical output; they all collapse to the
same commit_body call.
t7509-commit-authorship.sh defined its own local message_body() helper
around the idiom instead of spelling it out at each call site; remove the
helper and convert its six call sites to commit_body directly.
Two sites needed more than a mechanical substitution:
* t7600.sh ("merge --no-ff --edit") greps the raw commit object for a
phrase before stripping its header for the final comparison. The
phrase is part of the commit body, not the header, so the grep can
run against the already-stripped body instead, letting both steps
share one commit_body call.
* t3900-i18n-commit.sh pipes the stripped body into "iconv" to test
re-encoding. Piping commit_body's output into "iconv" would reintroduce
an exit-code hole one line after removing it elsewhere, so this site
writes the body to a file first and reads that, keeping the &&-chain
intact.
Some greps for sed -e "1,/^\*$/d" left unconverted, as they are not extracting a commit's message body:
* t9001-send-email.sh strips mail headers from a message file, not a
commit object.
* t1450-fsck.sh strips the header off a hand-built commit object while
constructing a malformed one for fsck to reject.
* t4014-format-patch.sh runs the same sed address on a ".patch" file,
with an additional expression.
All converted files pass in full, and a deliberately failing
"git cat-file" now fails a converted test that previously passed.
Signed-off-by: Shlok Kulshreshtha <diy2903@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Shlok Kulshreshtha committedJul 27, 2026 at 15:26 UTC9539653b71ed1ab37302574f96544013b8829eb9
13 files changed+72-123
t/t3404-rebase-interactive.sh
+1-1
index e64816770a..a952e2b49d 100755--- a/t/t3404-rebase-interactive.sh+++ b/t/t3404-rebase-interactive.sh@@ -484,7 +484,7 @@ test_expect_success 'squash and fixup generate correct log messages' ' EXPECT_HEADER_COUNT=4 \ git rebase -i $base ) &&- git cat-file commit HEAD | sed -e 1,/^\$/d > actual-squash-fixup &&+ commit_body HEAD >actual-squash-fixup && test_cmp expect-squash-fixup actual-squash-fixup && git cat-file commit HEAD@{2} >actual && test_grep "^# This is a combination of 3 commits\." actual &&
t/t3405-rebase-malformed.sh
+4-4
index 2524331861..271195fc11 100755--- a/t/t3405-rebase-malformed.sh+++ b/t/t3405-rebase-malformed.sh@@ -37,7 +37,7 @@ test_expect_success setup ' test_tick && git commit -F F &&- git cat-file commit HEAD | sed -e "1,/^\$/d" >F0 &&+ commit_body HEAD >F0 && git checkout diff-in-message && echo "commit log message containing a diff" >G &&@@ -48,7 +48,7 @@ test_expect_success setup ' test_tick && git commit -F G &&- git cat-file commit HEAD | sed -e "1,/^\$/d" >G0 &&+ commit_body HEAD >G0 && git checkout empty-message-merge && echo file3 >file3 &&@@ -66,7 +66,7 @@ test_expect_success setup ' test_expect_success 'rebase commit with multi-line subject' ' git rebase main multi-line-subject &&- git cat-file commit HEAD | sed -e "1,/^\$/d" >F1 &&+ commit_body HEAD >F1 && test_cmp F0 F1 && test_cmp F F0@@ -74,7 +74,7 @@ test_expect_success 'rebase commit with multi-line subject' ' test_expect_success 'rebase commit with diff in message' ' git rebase main diff-in-message &&- git cat-file commit HEAD | sed -e "1,/^$/d" >G1 &&+ commit_body HEAD >G1 && test_cmp G0 G1 && test_cmp G G0 '
t/t3408-rebase-multi-line.sh
+2-2
index cde3562e3a..2ab89e1a7d 100755--- a/t/t3408-rebase-multi-line.sh+++ b/t/t3408-rebase-multi-line.sh@@ -50,8 +50,8 @@ test_expect_success rebase ' git checkout side && git rebase main &&- git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&- git cat-file commit side@{1} | sed -e "1,/^\$/d" >expect &&+ commit_body HEAD >actual &&+ commit_body side@{1} >expect && test_cmp expect actual '
t/t3434-rebase-i18n.sh
+1-2
index 8c94fdffc4..0f93a239f8 100755--- a/t/t3434-rebase-i18n.sh+++ b/t/t3434-rebase-i18n.sh@@ -27,8 +27,7 @@ fi compare_msg () { iconv -f "$2" -t "$3" "$TEST_DIRECTORY/t3434/$1" >expect &&- git cat-file commit HEAD >raw &&- sed "1,/^$/d" raw >actual &&+ commit_body HEAD >actual && test_cmp expect actual }