From: Francesco Paparatto <francescopaparatto@gmail.com>
To: sunshine@sunshineco.com
Cc: francescopaparatto@gmail.com, git@vger.kernel.org,
Junio C Hamano <gitster@pobox.com>
Subject: [PATCH v2] t3310: avoid hiding failures from rev-parse in command substitutions
Date: Thu, 5 Mar 2026 10:06:02 +0100 [thread overview]
Message-ID: <20260305090602.22436-1-francescopaparatto@gmail.com> (raw)
In-Reply-To: <CAPig+cTHyB2sbBOELPb2=B5sU69OzSPU0JVn0p=2qMp=0=8vEg@mail.gmail.com>
Running `git` commands inside command substitutions like
test "$(git rev-parse A)" = "$(git rev-parse B)"
can hide failures from the `git` invocations and provide little
diagnostic information when `test` fails.
Use `test_cmp` when comparing against a stored expected value so
mismatches show both expected and actual output. Use `test_cmp_rev`
when comparing two revisions. These helpers produce clearer failure
output, making it easier to understand what went wrong.
Suggested-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Francesco Paparatto <francescopaparatto@gmail.com>
---
t/t3310-notes-merge-manual-resolve.sh | 60 ++++++++++++---------------
1 file changed, 27 insertions(+), 33 deletions(-)
diff --git a/t/t3310-notes-merge-manual-resolve.sh b/t/t3310-notes-merge-manual-resolve.sh
index 92a5951331..64c0a753ff 100755
--- a/t/t3310-notes-merge-manual-resolve.sh
+++ b/t/t3310-notes-merge-manual-resolve.sh
@@ -227,8 +227,8 @@ test_expect_success 'merge z into m (== y) with default ("manual") resolver => C
# Verify that current notes tree (pre-merge) has not changed (m == y)
verify_notes y &&
verify_notes m &&
- m=$(git rev-parse refs/notes/m) &&
- test "$m" = "$(cat pre_merge_y)"
+ git rev-parse refs/notes/m >actual &&
+ test_cmp pre_merge_y actual
'
cat <<EOF | sort >expect_notes_z
@@ -376,10 +376,10 @@ EOF
git notes merge --commit &&
notes_merge_files_gone &&
# Merge commit has pre-merge y and pre-merge z as parents
- m1=$(git rev-parse refs/notes/m^1) &&
- m2=$(git rev-parse refs/notes/m^2) &&
- test "$m1" = "$(cat pre_merge_y)" &&
- test "$m2" = "$(cat pre_merge_z)" &&
+ git rev-parse refs/notes/m^1 >actual &&
+ test_cmp pre_merge_y actual &&
+ git rev-parse refs/notes/m^2 >actual &&
+ test_cmp pre_merge_z actual &&
# Merge commit mentions the notes refs merged
git log -1 --format=%B refs/notes/m > merge_commit_msg &&
grep -q refs/notes/m merge_commit_msg &&
@@ -431,16 +431,16 @@ test_expect_success 'redo merge of z into m (== y) with default ("manual") resol
# Verify that current notes tree (pre-merge) has not changed (m == y)
verify_notes y &&
verify_notes m &&
- m=$(git rev-parse refs/notes/m) &&
- test "$m" = "$(cat pre_merge_y)"
+ git rev-parse refs/notes/m >actual &&
+ test_cmp pre_merge_y actual
'
test_expect_success 'abort notes merge' '
git notes merge --abort &&
notes_merge_files_gone &&
# m has not moved (still == y)
- m=$(git rev-parse refs/notes/m) &&
- test "$m" = "$(cat pre_merge_y)" &&
+ git rev-parse refs/notes/m >actual &&
+ test_cmp pre_merge_y actual &&
# Verify that other notes refs has not changed (w, x, y and z)
verify_notes w &&
verify_notes x &&
@@ -465,8 +465,8 @@ test_expect_success 'redo merge of z into m (== y) with default ("manual") resol
# Verify that current notes tree (pre-merge) has not changed (m == y)
verify_notes y &&
verify_notes m &&
- m=$(git rev-parse refs/notes/m) &&
- test "$m" = "$(cat pre_merge_y)"
+ git rev-parse refs/notes/m >actual &&
+ test_cmp pre_merge_y actual
'
cat <<EOF | sort >expect_notes_m
@@ -506,10 +506,10 @@ EOF
git notes merge --commit &&
notes_merge_files_gone &&
# Merge commit has pre-merge y and pre-merge z as parents
- m1=$(git rev-parse refs/notes/m^1) &&
- m2=$(git rev-parse refs/notes/m^2) &&
- test "$m1" = "$(cat pre_merge_y)" &&
- test "$m2" = "$(cat pre_merge_z)" &&
+ git rev-parse refs/notes/m^1 >actual &&
+ test_cmp pre_merge_y actual &&
+ git rev-parse refs/notes/m^2 >actual &&
+ test_cmp pre_merge_z actual &&
# Merge commit mentions the notes refs merged
git log -1 --format=%B refs/notes/m > merge_commit_msg &&
grep -q refs/notes/m merge_commit_msg &&
@@ -547,8 +547,8 @@ test_expect_success 'redo merge of z into m (== y) with default ("manual") resol
# Verify that current notes tree (pre-merge) has not changed (m == y)
verify_notes y &&
verify_notes m &&
- m=$(git rev-parse refs/notes/m) &&
- test "$m" = "$(cat pre_merge_y)"
+ git rev-parse refs/notes/m >actual &&
+ test_cmp pre_merge_y actual
'
cp expect_notes_w expect_notes_m
@@ -557,9 +557,7 @@ cp expect_log_w expect_log_m
test_expect_success 'reset notes ref m to somewhere else (w)' '
git update-ref refs/notes/m refs/notes/w &&
verify_notes m &&
- m=$(git rev-parse refs/notes/m) &&
- w=$(git rev-parse refs/notes/w) &&
- test "$m" = "$w"
+ test_cmp_rev refs/notes/m refs/notes/w
'
test_expect_success 'fail to finalize conflicting merge if underlying ref has moved in the meantime (m != NOTES_MERGE_PARTIAL^1)' '
@@ -580,17 +578,15 @@ EOF
test_path_is_file .git/NOTES_MERGE_WORKTREE/$commit_sha3 &&
test_path_is_file .git/NOTES_MERGE_WORKTREE/$commit_sha4 &&
# Refs are unchanged
- m=$(git rev-parse refs/notes/m) &&
- w=$(git rev-parse refs/notes/w) &&
- y=$(git rev-parse refs/notes/y) &&
- p1=$(git rev-parse NOTES_MERGE_PARTIAL^1) &&
- test "$m" = "$w" &&
- test "$y" = "$p1" &&
- test "$m" != "$p1" &&
+ test_cmp_rev refs/notes/m refs/notes/w &&
+ test_cmp_rev refs/notes/y NOTES_MERGE_PARTIAL^1 &&
+ test_cmp_rev ! refs/notes/m NOTES_MERGE_PARTIAL^1 &&
# Mention refs/notes/m, and its current and expected value in output
test_grep -q "refs/notes/m" output &&
- test_grep -q "$m" output &&
- test_grep -q "$p1" output &&
+ git rev-parse refs/notes/m >actual &&
+ test_grep -q "$(cat actual)" output &&
+ git rev-parse NOTES_MERGE_PARTIAL^1 >actual &&
+ test_grep -q "$(cat actual)" output &&
# Verify that other notes refs has not changed (w, x, y and z)
verify_notes w &&
verify_notes x &&
@@ -602,9 +598,7 @@ test_expect_success 'resolve situation by aborting the notes merge' '
git notes merge --abort &&
notes_merge_files_gone &&
# m has not moved (still == w)
- m=$(git rev-parse refs/notes/m) &&
- w=$(git rev-parse refs/notes/w) &&
- test "$m" = "$w" &&
+ test_cmp_rev refs/notes/m refs/notes/w &&
# Verify that other notes refs has not changed (w, x, y and z)
verify_notes w &&
verify_notes x &&
--
2.52.0
next prev parent reply other threads:[~2026-03-05 9:06 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-04 12:19 [PATCH] t3310: avoid hiding failures from rev-parse in command substitutions Francesco Paparatto
2026-03-04 22:21 ` Eric Sunshine
2026-03-05 9:06 ` Francesco Paparatto [this message]
2026-03-05 19:13 ` [PATCH v2] " Junio C Hamano
2026-03-05 22:34 ` Eric Sunshine
2026-03-05 22:49 ` Francesco Paparatto
2026-03-05 23:06 ` Junio C Hamano
2026-03-05 23:14 ` Junio C Hamano
2026-03-05 22:42 ` Francesco Paparatto
2026-03-05 22:51 ` [PATCH v3] " Francesco Paparatto
2026-03-07 6:29 ` Eric Sunshine
2026-03-07 10:17 ` Francesco Paparatto
2026-03-07 10:36 ` [PATCH v4] " Francesco Paparatto
2026-03-08 4:13 ` Eric Sunshine
2026-03-08 6:04 ` Junio C Hamano
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=20260305090602.22436-1-francescopaparatto@gmail.com \
--to=francescopaparatto@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=sunshine@sunshineco.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