t: add and use a commit_body test helper
cover t: add and use a commit_body test helper
While reviewing "t7614: avoid hiding git's exit code in a pipe" (now in master as b6b276974e), Junio pointed out that the pattern fixed there by hand -- "cat-file the commit object, and strip away the object header with sed" -- recurs throughout the test suite, and suggested factoring it into a helper (cf. <[email protected]>):
commit_body () {
git cat-file commit "$1" >.commit &&
sed -e "1,/^$/d" .commit &&
rm -f .commit
}I said I would take this up as a follow-up once t7614 landed. It has, so here it is.
Scope:
1/2 adds the helper to t/test-lib-functions.sh, following Junio's
sketch, with a t/README entry.
2/2 converts the existing call sites: 60 sites across 11 files.
The idiom appears in four equivalent spellings (piped or written to a file first, "sed -e" or plain "sed", "\$" or "$" in the address) that all produce byte-identical output and collapse to the same commit_body call. Two sites needed more than a mechanical substitution and are explained individually in that commit's message; a few more are left alone because they are not extracting a commit's message body at all (email headers, a hand-built object for fsck, a .patch file).
Converting the piped sites also closes the same exit-code hole t7614
fixed: the exit status of a pipeline is that of its last command, so a crashing "git cat-file" was previously masked by "sed" succeeding on empty input.
Verification: all 11 touched test scripts pass in full (build clean, no new failures), and a deliberately failing "git cat-file" now fails a converted test that previously passed, confirming the exit-code fix is real.
Shlok Kulshreshtha (2):
test-lib-functions: add commit_body helper
t: use commit_body to extract commit message bodies
t/README | 11 ++++ t/t3405-rebase-malformed.sh | 8 +-- t/t3408-rebase-multi-line.sh | 4 +- t/t3434-rebase-i18n.sh | 3 +- t/t3900-i18n-commit.sh | 4 +- t/t4150-am.sh | 8 +-- t/t7500-commit-template-squash-signoff.sh | 4 +- t/t7501-commit-basic-functionality.sh | 21 +++---- t/t7502-commit-porcelain.sh | 77 ++++++++--------------- t/t7600-merge.sh | 14 ++--- t/t7604-merge-custom-message.sh | 18 ++---- t/t7614-merge-signoff.sh | 9 +-- t/test-lib-functions.sh | 8 +++ 13 files changed, 81 insertions(+), 108 deletions(-)
Signature · 1 line
2.52.0
PATCH 1/2 test-lib-functions: add commit_body helper
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.
--- t/README | 11 +++++++++++ t/test-lib-functions.sh | 8 ++++++++ 2 files changed, 19 insertions(+)
t/README +11 -0
@@ -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
t/test-lib-functions.sh +8 -0
@@ -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"
Signature · 1 line
2.52.0
PATCH 2/2 t: use commit_body to extract commit message bodies
In reply to Shlok KulshreshthaReplace the "git cat-file commit | sed" idiom with commit_body across the test suite: 60 sites in 11 files. 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.
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.
--- t/t3405-rebase-malformed.sh | 8 +-- t/t3408-rebase-multi-line.sh | 4 +- t/t3434-rebase-i18n.sh | 3 +- t/t3900-i18n-commit.sh | 4 +- t/t4150-am.sh | 8 +-- t/t7500-commit-template-squash-signoff.sh | 4 +- t/t7501-commit-basic-functionality.sh | 21 +++---- t/t7502-commit-porcelain.sh | 77 ++++++++--------------- t/t7600-merge.sh | 14 ++--- t/t7604-merge-custom-message.sh | 18 ++---- t/t7614-merge-signoff.sh | 9 +-- 11 files changed, 62 insertions(+), 108 deletions(-)
t/t3405-rebase-malformed.sh +4 -4
@@ -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
@@ -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
@@ -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 }
t/t3900-i18n-commit.sh +2 -2
@@ -232,8 +232,8 @@ test_commit_autosquash_multi_encoding () { git rev-list HEAD >actual && test_line_count = 3 actual && iconv -f $old -t UTF-8 "$TEST_DIRECTORY"/t3900/$msg >expect && - git cat-file commit HEAD^ >raw && - (sed "1,/^$/d" raw | iconv -f $new -t utf-8) >actual && + commit_body HEAD^ >raw && + iconv -f $new -t utf-8 <raw >actual && test_cmp expect actual ' }
t/t4150-am.sh +4 -4
@@ -1018,7 +1018,7 @@ test_expect_success 'am -s unexpected trailer block' ' Signed-off-by: J C H <[email protected]> EOF git commit -F msg && - git cat-file commit HEAD | sed -e "1,/^$/d" >original && + commit_body HEAD >original && git format-patch --stdout -1 >patch && git reset --hard HEAD^ &&
@@ -1027,7 +1027,7 @@ test_expect_success 'am -s unexpected trailer block' ' cat original && echo "Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" ) >expect && - git cat-file commit HEAD | sed -e "1,/^$/d" >actual && + commit_body HEAD >actual && test_cmp expect actual && cat >msg <<-\EOF &&
@@ -1038,7 +1038,7 @@ test_expect_success 'am -s unexpected trailer block' ' EOF git reset HEAD^ && git commit -F msg file && - git cat-file commit HEAD | sed -e "1,/^$/d" >original && + commit_body HEAD >original && git format-patch --stdout -1 >patch && git reset --hard HEAD^ &&
@@ -1049,7 +1049,7 @@ test_expect_success 'am -s unexpected trailer block' ' echo && echo "Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" ) >expect && - git cat-file commit HEAD | sed -e "1,/^$/d" >actual && + commit_body HEAD >actual && test_cmp expect actual '
t/t7500-commit-template-squash-signoff.sh +2 -2
@@ -59,7 +59,7 @@ test_expect_success 'nonexistent template file in config should return error' ' test_expect_success 'nonexistent optional template file in config' ' test_config commit.template ":(optional)$(pwd)"/notexist && GIT_EDITOR="echo hello >" git commit --allow-empty && - git cat-file commit HEAD | sed -e "1,/^$/d" >actual && + commit_body HEAD >actual && echo hello >expect && test_cmp expect actual '
@@ -204,7 +204,7 @@ EOF test_expect_success '--signoff' ' echo "yet another content *narf*" >> foo && echo "zort" | git commit -s -F - foo && - git cat-file commit HEAD | sed "1,/^\$/d" > output && + commit_body HEAD >output && test_cmp expect output '
t/t7501-commit-basic-functionality.sh +7 -14
@@ -491,8 +491,7 @@ test_expect_success 'sign off (1)' ' echo 1 >positive && git add positive && git commit -s -m "thank you" && - git cat-file commit HEAD >commit && - sed -e "1,/^\$/d" commit >actual && + commit_body HEAD >actual && ( echo thank you && echo &&
@@ -511,8 +510,7 @@ test_expect_success 'sign off (2)' ' git commit -s -m "thank you $existing" && - git cat-file commit HEAD >commit && - sed -e "1,/^\$/d" commit >actual && + commit_body HEAD >actual && ( echo thank you && echo &&
@@ -532,8 +530,7 @@ test_expect_success 'signoff gap' ' git commit -s -m "welcome $alt" && - git cat-file commit HEAD >commit && - sed -e "1,/^\$/d" commit >actual && + commit_body HEAD >actual && ( echo welcome && echo &&
@@ -553,8 +550,7 @@ test_expect_success 'signoff gap 2' ' We have now $alt" && - git cat-file commit HEAD >commit && - sed -e "1,/^\$/d" commit >actual && + commit_body HEAD >actual && ( echo welcome && echo &&
@@ -575,8 +571,7 @@ test_expect_success 'signoff respects trailer config' ' non-trailer line Myfooter: x" && - git cat-file commit HEAD >commit && - sed -e "1,/^\$/d" commit >actual && + commit_body HEAD >actual && ( echo subject && echo &&
@@ -593,8 +588,7 @@ Myfooter: x" && non-trailer line Myfooter: x" && - git cat-file commit HEAD >commit && - sed -e "1,/^\$/d" commit >actual && + commit_body HEAD >actual && ( echo subject && echo &&
@@ -626,8 +620,7 @@ test_expect_success 'multiple -m' ' >negative && git add negative && git commit -m "one" -m "two" -m "three" && - git cat-file commit HEAD >commit && - sed -e "1,/^\$/d" commit >actual && + commit_body HEAD >actual && ( echo one && echo &&
t/t7502-commit-porcelain.sh +26 -51
233 lines not on this page · raw message
t/t7600-merge.sh +5 -9
@@ -332,8 +332,7 @@ test_expect_success 'merge --squash c3 with c7' ' # Conflicts: # file EOF - git cat-file commit HEAD >raw && - sed -e "1,/^$/d" raw >actual && + commit_body HEAD >actual && test_cmp expect actual '
@@ -363,8 +362,7 @@ test_expect_success 'merge c3 with c7 with commit.cleanup = scissors' ' # Conflicts: # file EOF - git cat-file commit HEAD >raw && - sed -e "1,/^$/d" raw >actual && + commit_body HEAD >actual && test_cmp expect actual '
@@ -387,8 +385,7 @@ test_expect_success 'merge c3 with c7 with --squash commit.cleanup = scissors' ' # Conflicts: # file EOF - git cat-file commit HEAD >raw && - sed -e "1,/^$/d" raw >actual && + commit_body HEAD >actual && test_cmp expect actual '
@@ -989,9 +986,8 @@ test_expect_success 'merge --no-ff --edit' ' git reset --hard c0 && EDITOR=./editor git merge --no-ff --edit c1 && verify_parents $c0 $c1 && - git cat-file commit HEAD >raw && - test_grep "work done on the side branch" raw && - sed "1,/^$/d" >actual raw && + commit_body HEAD >actual && + test_grep "work done on the side branch" actual && test_cmp expected actual '
t/t7604-merge-custom-message.sh +6 -12
@@ -36,16 +36,14 @@ test_expect_success 'setup' ' test_expect_success 'merge c2 with a custom message' ' git reset --hard c1 && git merge -m "$(cat exp.subject)" c2 && - git cat-file commit HEAD >raw && - sed -e "1,/^$/d" raw >actual && + commit_body HEAD >actual && test_cmp exp.subject actual ' test_expect_success 'merge --log appends to custom message' ' git reset --hard c1 && git merge --log -m "$(cat exp.subject)" c2 && - git cat-file commit HEAD >raw && - sed -e "1,/^$/d" raw >actual && + commit_body HEAD >actual && test_cmp exp.log actual '
@@ -61,8 +59,7 @@ test_expect_success 'prepare file with comment line and trailing newlines' ' test_expect_success 'cleanup commit messages (verbatim option)' ' git reset --hard c1 && git merge --cleanup=verbatim -F expect c2 && - git cat-file commit HEAD >raw && - sed -e "1,/^$/d" raw >actual && + commit_body HEAD >actual && test_cmp expect actual '
@@ -71,8 +68,7 @@ test_expect_success 'cleanup commit messages (whitespace option)' ' test_write_lines "" "# text" "" >text && echo "# text" >expect && git merge --cleanup=whitespace -F text c2 && - git cat-file commit HEAD >raw && - sed -e "1,/^$/d" raw >actual && + commit_body HEAD >actual && test_cmp expect actual '
@@ -97,8 +93,7 @@ test_expect_success 'cleanup merge messages (scissors option)' ' # to be kept, too EOF git merge --cleanup=scissors -e -F text c2 && - git cat-file commit HEAD >raw && - sed -e "1,/^$/d" raw >actual && + commit_body HEAD >actual && test_cmp expect actual '
@@ -107,8 +102,7 @@ test_expect_success 'cleanup commit messages (strip option)' ' test_write_lines "" "# text" "sample" "" >text && echo sample >expect && git merge --cleanup=strip -F text c2 && - git cat-file commit HEAD >raw && - sed -e "1,/^$/d" raw >actual && + commit_body HEAD >actual && test_cmp expect actual '
t/t7614-merge-signoff.sh +3 -6
@@ -45,8 +45,7 @@ test_expect_success 'git merge --signoff adds a sign-off line' ' test_commit main-branch-2 file2 2 && git checkout other-branch && git merge main --signoff --no-edit && - git cat-file commit HEAD >commit && - sed -e "1,/^\$/d" commit >actual && + commit_body HEAD >actual && test_cmp expected-signed actual '
@@ -56,8 +55,7 @@ test_expect_success 'git merge does not add a sign-off line' ' test_commit main-branch-3 file3 3 && git checkout other-branch && git merge main --no-edit && - git cat-file commit HEAD >commit && - sed -e "1,/^\$/d" commit >actual && + commit_body HEAD >actual && test_cmp expected-unsigned actual '
@@ -67,8 +65,7 @@ test_expect_success 'git merge --no-signoff flag cancels --signoff flag' ' test_commit main-branch-4 file4 4 && git checkout other-branch && git merge main --no-edit --signoff --no-signoff && - git cat-file commit HEAD >commit && - sed -e "1,/^\$/d" commit >actual && + commit_body HEAD >actual && test_cmp expected-unsigned actual '
Signature · 1 line
2.52.0
Quoted 6 lines · Shlok Kulshreshtha
t/README | 11 ++++ t/t3405-rebase-malformed.sh | 8 +-- t/t3408-rebase-multi-line.sh | 4 +- t/t3434-rebase-i18n.sh | 3 +- t/t3900-i18n-commit.sh | 4 +- t/t4150-am.sh | 8 +--
Quoted 8 lines
t/t7500-commit-template-squash-signoff.sh | 4 +- t/t7501-commit-basic-functionality.sh | 21 +++---- t/t7502-commit-porcelain.sh | 77 ++++++++--------------- t/t7600-merge.sh | 14 ++--- t/t7604-merge-custom-message.sh | 18 ++---- t/t7614-merge-signoff.sh | 9 +-- t/test-lib-functions.sh | 8 +++ 13 files changed, 81 insertions(+), 108 deletions(-)
Doesn't 'message_body' t7509 has follow the same pattern to hide exit code from 'git cat-file commit'?
Thanks.
Quoted 2 lines · Junio C Hamano
Doesn't '
message_body' t7509 has follow the same pattern to hide exit code from 'git cat-file commit'?
Yes, you are right, I had missed that one. t7509 defines its own local message_body() helper:
message_body () {
git cat-file commit "$1" |
sed -e '1,/^$/d'
}which pipes "git cat-file commit" into "sed", the same exit-code-hiding idiom commit_body was introduced to replace. While rechecking, I found one more site with the same problem in t3404-rebase-interactive.sh, a spacing variant of the idiom ("sed -e 1,/^\$/d" without quotes around the address) that didn't match the four spellings I had searched for in the original patch.
I've replaced both -- the message_body helper (and its call sites) in t7509, and the inline pipe in t3404 -- with commit_body. Will send a v2 with these folded in.
Thanks.
v2 cover t: add and use a commit_body test helper
In reply to Junio C HamanoJunio pointed out that t7509-commit-authorship.sh defines its own local message_body() helper that wraps the same "git cat-file commit | sed" idiom commit_body was introduced to replace, which the first version of this series missed. Rechecking the whole idiom by its sed address, rather than by grepping for "cat-file", turned up one more inline occurrence with a spacing/escaping variant in t3404-rebase-interactive.sh that also didn't match the four spellings enumerated in v1.
Changes since v1:
2/2: fold in t7509's message_body helper (drop it, convert its six
call sites to commit_body) and the missed inline site in t3404. Site count is now 61 in 12 files, plus the removed helper.
Shlok Kulshreshtha (2):
test-lib-functions: add commit_body helper
t: use commit_body to extract commit message bodies
t/README | 11 ++++ t/t3404-rebase-interactive.sh | 2 +- t/t3405-rebase-malformed.sh | 8 +-- t/t3408-rebase-multi-line.sh | 4 +- t/t3434-rebase-i18n.sh | 3 +- t/t3900-i18n-commit.sh | 4 +- t/t4150-am.sh | 8 +-- t/t7500-commit-template-squash-signoff.sh | 4 +- t/t7501-commit-basic-functionality.sh | 21 +++---- t/t7502-commit-porcelain.sh | 77 ++++++++--------------- t/t7509-commit-authorship.sh | 23 +++---- t/t7600-merge.sh | 14 ++--- t/t7604-merge-custom-message.sh | 18 ++---- t/t7614-merge-signoff.sh | 9 +-- t/test-lib-functions.sh | 8 +++ 15 files changed, 91 insertions(+), 123 deletions(-)
Signature · 1 line
2.52.0
PATCH v2 1/2 test-lib-functions: add commit_body helper
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.
--- t/README | 11 +++++++++++ t/test-lib-functions.sh | 8 ++++++++ 2 files changed, 19 insertions(+)
t/README +11 -0
@@ -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
t/test-lib-functions.sh +8 -0
@@ -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"
Signature · 1 line
2.52.0
PATCH v2 2/2 t: use commit_body to extract commit message bodies
In reply to Shlok KulshreshthaReplace 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.
--- t/t3404-rebase-interactive.sh | 2 +- t/t3405-rebase-malformed.sh | 8 +-- t/t3408-rebase-multi-line.sh | 4 +- t/t3434-rebase-i18n.sh | 3 +- t/t3900-i18n-commit.sh | 4 +- t/t4150-am.sh | 8 +-- t/t7500-commit-template-squash-signoff.sh | 4 +- t/t7501-commit-basic-functionality.sh | 21 +++---- t/t7502-commit-porcelain.sh | 77 ++++++++--------------- t/t7509-commit-authorship.sh | 23 +++---- t/t7600-merge.sh | 14 ++--- t/t7604-merge-custom-message.sh | 18 ++---- t/t7614-merge-signoff.sh | 9 +-- 13 files changed, 72 insertions(+), 123 deletions(-)
t/t3404-rebase-interactive.sh +1 -1
@@ -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
@@ -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
@@ -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
@@ -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 }
t/t3900-i18n-commit.sh +2 -2
@@ -232,8 +232,8 @@ test_commit_autosquash_multi_encoding () { git rev-list HEAD >actual && test_line_count = 3 actual && iconv -f $old -t UTF-8 "$TEST_DIRECTORY"/t3900/$msg >expect && - git cat-file commit HEAD^ >raw && - (sed "1,/^$/d" raw | iconv -f $new -t utf-8) >actual && + commit_body HEAD^ >raw && + iconv -f $new -t utf-8 <raw >actual && test_cmp expect actual ' }
t/t4150-am.sh +4 -4
@@ -1018,7 +1018,7 @@ test_expect_success 'am -s unexpected trailer block' ' Signed-off-by: J C H <[email protected]> EOF git commit -F msg && - git cat-file commit HEAD | sed -e "1,/^$/d" >original && + commit_body HEAD >original && git format-patch --stdout -1 >patch && git reset --hard HEAD^ &&
@@ -1027,7 +1027,7 @@ test_expect_success 'am -s unexpected trailer block' ' cat original && echo "Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" ) >expect && - git cat-file commit HEAD | sed -e "1,/^$/d" >actual && + commit_body HEAD >actual && test_cmp expect actual && cat >msg <<-\EOF &&
@@ -1038,7 +1038,7 @@ test_expect_success 'am -s unexpected trailer block' ' EOF git reset HEAD^ && git commit -F msg file && - git cat-file commit HEAD | sed -e "1,/^$/d" >original && + commit_body HEAD >original && git format-patch --stdout -1 >patch && git reset --hard HEAD^ &&
@@ -1049,7 +1049,7 @@ test_expect_success 'am -s unexpected trailer block' ' echo && echo "Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" ) >expect && - git cat-file commit HEAD | sed -e "1,/^$/d" >actual && + commit_body HEAD >actual && test_cmp expect actual '
t/t7500-commit-template-squash-signoff.sh +2 -2
@@ -59,7 +59,7 @@ test_expect_success 'nonexistent template file in config should return error' ' test_expect_success 'nonexistent optional template file in config' ' test_config commit.template ":(optional)$(pwd)"/notexist && GIT_EDITOR="echo hello >" git commit --allow-empty && - git cat-file commit HEAD | sed -e "1,/^$/d" >actual && + commit_body HEAD >actual && echo hello >expect && test_cmp expect actual '
@@ -204,7 +204,7 @@ EOF test_expect_success '--signoff' ' echo "yet another content *narf*" >> foo && echo "zort" | git commit -s -F - foo && - git cat-file commit HEAD | sed "1,/^\$/d" > output && + commit_body HEAD >output && test_cmp expect output '
t/t7501-commit-basic-functionality.sh +7 -14
@@ -491,8 +491,7 @@ test_expect_success 'sign off (1)' ' echo 1 >positive && git add positive && git commit -s -m "thank you" && - git cat-file commit HEAD >commit && - sed -e "1,/^\$/d" commit >actual && + commit_body HEAD >actual && ( echo thank you && echo &&
@@ -511,8 +510,7 @@ test_expect_success 'sign off (2)' ' git commit -s -m "thank you $existing" && - git cat-file commit HEAD >commit && - sed -e "1,/^\$/d" commit >actual && + commit_body HEAD >actual && ( echo thank you && echo &&
@@ -532,8 +530,7 @@ test_expect_success 'signoff gap' ' git commit -s -m "welcome $alt" && - git cat-file commit HEAD >commit && - sed -e "1,/^\$/d" commit >actual && + commit_body HEAD >actual && ( echo welcome && echo &&
@@ -553,8 +550,7 @@ test_expect_success 'signoff gap 2' ' We have now $alt" && - git cat-file commit HEAD >commit && - sed -e "1,/^\$/d" commit >actual && + commit_body HEAD >actual && ( echo welcome && echo &&
@@ -575,8 +571,7 @@ test_expect_success 'signoff respects trailer config' ' non-trailer line Myfooter: x" && - git cat-file commit HEAD >commit && - sed -e "1,/^\$/d" commit >actual && + commit_body HEAD >actual && ( echo subject && echo &&
@@ -593,8 +588,7 @@ Myfooter: x" && non-trailer line Myfooter: x" && - git cat-file commit HEAD >commit && - sed -e "1,/^\$/d" commit >actual && + commit_body HEAD >actual && ( echo subject && echo &&
@@ -626,8 +620,7 @@ test_expect_success 'multiple -m' ' >negative && git add negative && git commit -m "one" -m "two" -m "three" && - git cat-file commit HEAD >commit && - sed -e "1,/^\$/d" commit >actual && + commit_body HEAD >actual && ( echo one && echo &&
t/t7502-commit-porcelain.sh +26 -51
233 lines not on this page · raw message
t/t7509-commit-authorship.sh +9 -14
@@ -12,11 +12,6 @@ author_header () { sed -n -e '/^$/q' -e '/^author /p' } -message_body () { - git cat-file commit "$1" | - sed -e '1,/^$/d' -} - test_expect_success '-C option copies authorship and message' ' test_commit --author Frigate\ \<[email protected]\> \ "Initial Commit" foo Initial Initial &&
@@ -27,8 +22,8 @@ test_expect_success '-C option copies authorship and message' ' author_header HEAD >actual && test_cmp expect actual && - message_body Initial >expect && - message_body HEAD >actual && + commit_body Initial >expect && + commit_body HEAD >actual && test_cmp expect actual '
@@ -40,8 +35,8 @@ test_expect_success '-C option copies only the message with --reset-author' ' author_header HEAD >actual && test_cmp expect actual && - message_body Initial >expect && - message_body HEAD >actual && + commit_body Initial >expect && + commit_body HEAD >actual && test_cmp expect actual '
@@ -62,8 +57,8 @@ test_expect_success '-c option copies only the message with --reset-author' ' author_header HEAD >actual && test_cmp expect actual && - message_body Initial >expect && - message_body HEAD >actual && + commit_body Initial >expect && + commit_body HEAD >actual && test_cmp expect actual '
@@ -77,7 +72,7 @@ test_expect_success '--amend option copies authorship' ' test_cmp expect actual && echo "amend test" >expect && - message_body HEAD >actual && + commit_body HEAD >actual && test_cmp expect actual '
@@ -124,7 +119,7 @@ test_expect_success '--reset-author makes the commit ours even with --amend opti test_cmp expect actual && echo "Changed again" >expect && - message_body HEAD >actual && + commit_body HEAD >actual && test_cmp expect actual '
@@ -157,7 +152,7 @@ test_expect_success 'commit respects CHERRY_PICK_HEAD and MERGE_MSG' ' test_cmp expect actual && echo "This is a MERGE_MSG" >expect && - message_body HEAD >actual && + commit_body HEAD >actual && test_cmp expect actual '
t/t7600-merge.sh +5 -9
@@ -332,8 +332,7 @@ test_expect_success 'merge --squash c3 with c7' ' # Conflicts: # file EOF - git cat-file commit HEAD >raw && - sed -e "1,/^$/d" raw >actual && + commit_body HEAD >actual && test_cmp expect actual '
@@ -363,8 +362,7 @@ test_expect_success 'merge c3 with c7 with commit.cleanup = scissors' ' # Conflicts: # file EOF - git cat-file commit HEAD >raw && - sed -e "1,/^$/d" raw >actual && + commit_body HEAD >actual && test_cmp expect actual '
@@ -387,8 +385,7 @@ test_expect_success 'merge c3 with c7 with --squash commit.cleanup = scissors' ' # Conflicts: # file EOF - git cat-file commit HEAD >raw && - sed -e "1,/^$/d" raw >actual && + commit_body HEAD >actual && test_cmp expect actual '
@@ -989,9 +986,8 @@ test_expect_success 'merge --no-ff --edit' ' git reset --hard c0 && EDITOR=./editor git merge --no-ff --edit c1 && verify_parents $c0 $c1 && - git cat-file commit HEAD >raw && - test_grep "work done on the side branch" raw && - sed "1,/^$/d" >actual raw && + commit_body HEAD >actual && + test_grep "work done on the side branch" actual && test_cmp expected actual '
t/t7604-merge-custom-message.sh +6 -12
@@ -36,16 +36,14 @@ test_expect_success 'setup' ' test_expect_success 'merge c2 with a custom message' ' git reset --hard c1 && git merge -m "$(cat exp.subject)" c2 && - git cat-file commit HEAD >raw && - sed -e "1,/^$/d" raw >actual && + commit_body HEAD >actual && test_cmp exp.subject actual ' test_expect_success 'merge --log appends to custom message' ' git reset --hard c1 && git merge --log -m "$(cat exp.subject)" c2 && - git cat-file commit HEAD >raw && - sed -e "1,/^$/d" raw >actual && + commit_body HEAD >actual && test_cmp exp.log actual '
@@ -61,8 +59,7 @@ test_expect_success 'prepare file with comment line and trailing newlines' ' test_expect_success 'cleanup commit messages (verbatim option)' ' git reset --hard c1 && git merge --cleanup=verbatim -F expect c2 && - git cat-file commit HEAD >raw && - sed -e "1,/^$/d" raw >actual && + commit_body HEAD >actual && test_cmp expect actual '
@@ -71,8 +68,7 @@ test_expect_success 'cleanup commit messages (whitespace option)' ' test_write_lines "" "# text" "" >text && echo "# text" >expect && git merge --cleanup=whitespace -F text c2 && - git cat-file commit HEAD >raw && - sed -e "1,/^$/d" raw >actual && + commit_body HEAD >actual && test_cmp expect actual '
@@ -97,8 +93,7 @@ test_expect_success 'cleanup merge messages (scissors option)' ' # to be kept, too EOF git merge --cleanup=scissors -e -F text c2 && - git cat-file commit HEAD >raw && - sed -e "1,/^$/d" raw >actual && + commit_body HEAD >actual && test_cmp expect actual '
@@ -107,8 +102,7 @@ test_expect_success 'cleanup commit messages (strip option)' ' test_write_lines "" "# text" "sample" "" >text && echo sample >expect && git merge --cleanup=strip -F text c2 && - git cat-file commit HEAD >raw && - sed -e "1,/^$/d" raw >actual && + commit_body HEAD >actual && test_cmp expect actual '
t/t7614-merge-signoff.sh +3 -6
@@ -45,8 +45,7 @@ test_expect_success 'git merge --signoff adds a sign-off line' ' test_commit main-branch-2 file2 2 && git checkout other-branch && git merge main --signoff --no-edit && - git cat-file commit HEAD >commit && - sed -e "1,/^\$/d" commit >actual && + commit_body HEAD >actual && test_cmp expected-signed actual '
@@ -56,8 +55,7 @@ test_expect_success 'git merge does not add a sign-off line' ' test_commit main-branch-3 file3 3 && git checkout other-branch && git merge main --no-edit && - git cat-file commit HEAD >commit && - sed -e "1,/^\$/d" commit >actual && + commit_body HEAD >actual && test_cmp expected-unsigned actual '
@@ -67,8 +65,7 @@ test_expect_success 'git merge --no-signoff flag cancels --signoff flag' ' test_commit main-branch-4 file4 4 && git checkout other-branch && git merge main --no-edit --signoff --no-signoff && - git cat-file commit HEAD >commit && - sed -e "1,/^\$/d" commit >actual && + commit_body HEAD >actual && test_cmp expected-unsigned actual '
Signature · 1 line
2.52.0
Re: [PATCH v2 2/2] t: use commit_body to extract commit message bodies
Quoted 6 lines · Shlok Kulshreshtha
t/t3404-rebase-interactive.sh | 2 +- t/t3405-rebase-malformed.sh | 8 +-- t/t3408-rebase-multi-line.sh | 4 +- t/t3434-rebase-i18n.sh | 3 +- t/t3900-i18n-commit.sh | 4 +- t/t4150-am.sh | 8 +--
Quoted 8 lines
t/t7500-commit-template-squash-signoff.sh | 4 +- t/t7501-commit-basic-functionality.sh | 21 +++---- t/t7502-commit-porcelain.sh | 77 ++++++++--------------- t/t7509-commit-authorship.sh | 23 +++---- t/t7600-merge.sh | 14 ++--- t/t7604-merge-custom-message.sh | 18 ++---- t/t7614-merge-signoff.sh | 9 +-- 13 files changed, 72 insertions(+), 123 deletions(-)
I would not claim to have checked all of these changes, but I did spot check a handful and they all looked reasonable.
Shall we mark the topic for 'next'?
Thanks.
Re: [PATCH v2 2/2] t: use commit_body to extract commit message bodies
Quoted 4 lines · Junio C Hamano
I would not claim to have checked all of these changes, but I did spot check a handful and they all looked reasonable.
Shall we mark the topic for 'next'?
Yes, please.
To save you reading all 66 hunks: 63 of them are the same local swap, where the rev and the output file are unchanged and only the spelling differs.
-git cat-file commit HEAD | sed -e "1,/^\$/d" >actual +commit_body HEAD >actual
Each one can be confirmed by looking at the hunk alone.
The three hunks that are worth actual attention are:
* t7509-commit-authorship.sh, the hunk at author_header(). This one deletes the file's local message_body() helper rather than substituting anything; its call sites become commit_body elsewhere in the file.
* t7600-merge.sh, "merge --no-ff --edit". The test grepped the raw commit object for a phrase and then stripped the header for the comparison. The phrase is in the body rather than the header, so the grep now runs against the already-stripped body and both steps share one commit_body call.
* t3900-i18n-commit.sh, in test_commit_autosquash_multi_encoding(). The stripped body was piped into "iconv". Piping commit_body into "iconv" would reintroduce the exit-code hole,
so the body is written to a file and "iconv"
reads the file.
Everything else in the patch is the swap above.
Re: [PATCH v2 2/2] t: use commit_body to extract commit message bodies
Quoted 8 lines · Shlok Kulshreshtha
Quoted 4 lines · Junio C Hamano
I would not claim to have checked all of these changes, but I did spot check a handful and they all looked reasonable.
Shall we mark the topic for 'next'?
Yes, please.
The qutestion was not quite for you, but for those other people who are reading the list from sidelines. We all know that the original author of the patch wants their work in, so that does not work as a useful signal.
Quoted 11 lines
*
t7600-merge.sh, "merge --no-ff --edit". The test grepped the raw commit object for a phrase and then stripped the header for the comparison. The phrase is in the body rather than the header, so the grep now runs against the already-stripped body and both steps share onecommit_bodycall.*
t3900-i18n-commit.sh, intest_commit_autosquash_multi_encoding(). The stripped body was piped into "iconv". Pipingcommit_bodyinto "iconv" would reintroduce the exit-code hole,
so the body is written to a file and "iconv"
reads the file.
These are as the log message describes ;-) All looked good.
Thanks.