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

[PATCH 2/2] t5403: use test_cmp for post-checkout argument checks

From
Deveshi Dwivedi <deveshigurgaon@gmail.com>
Date
Jan 11, 2026, 07:29 UTC
Message-ID
<20260111072950.9463-3-deveshigurgaon@gmail.com>
In-Reply-To
<20260111072950.9463-1-deveshigurgaon@gmail.com>

Update check_post_checkout and the post-checkout hook implementation to use test_cmp instead of individual test commands. This provides better error messages when tests fail, making it easier to debug which specific argument (old ref, new ref, or flag) was incorrect.

The hook now outputs in key=value format which test_cmp can display clearly when there's a mismatch.

Signed-off-by: Deveshi Dwivedi <deveshigurgaon@gmail.com>
---
 t/t5403-post-checkout-hook.sh | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/t/t5403-post-checkout-hook.sh b/t/t5403-post-checkout-hook.sh
index 63a2221441..a50c8d0eee 100755
--- a/t/t5403-post-checkout-hook.sh
+++ b/t/t5403-post-checkout-hook.sh
@@ -12,13 +12,13 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
 # Helper function to check post-checkout hook arguments
 check_post_checkout () {
 	test "$#" = 4 || BUG "check_post_checkout takes 4 args"
-	read old new flag <"$1" &&
-	test "$old" = "$2" && test "$new" = "$3" && test "$flag" = "$4"
+	echo "old=$2 new=$3 flag=$4" >expect &&
+	test_cmp expect "$1"
 }
 
 test_expect_success setup '
 	test_hook --setup post-checkout <<-\EOF &&
-	echo "$@" >.git/post-checkout.args
+	echo "old=$1 new=$2 flag=$3" >.git/post-checkout.args
 	EOF
 	test_commit one &&
 	test_commit two &&
@@ -108,7 +108,7 @@ test_rebase --merge
 test_expect_success 'post-checkout hook is triggered by clone' '
 	mkdir -p templates/hooks &&
 	write_script templates/hooks/post-checkout <<-\EOF &&
-	echo "$@" >"$GIT_DIR/post-checkout.args"
+	echo "old=$1 new=$2 flag=$3" >"$GIT_DIR/post-checkout.args"
 	EOF
 	git clone --template=templates . clone3 &&
 	check_post_checkout clone3/.git/post-checkout.args \
-- 
2.52.0.230.gd8af7cadaa
Previous: Pushkar SinghNext: Deveshi Dwivedi
Message 7 of 14 in “t5403: improve post-checkout hook testing”
  1. 0/2 t5403: improve post-checkout hook testingDeveshi Dwivedi, Jan 11, 2026
  2. 1/2 t5403:introduce check_post_checkout helper functionDeveshi Dwivedi, Jan 11, 2026
  3. Eric SunshineJan 11, 2026
  4. Pushkar SinghJan 11, 2026
  5. Deveshi DwivediJan 12, 2026
  6. t5403: document check_post_checkout helperPushkar Singh, Jan 11, 2026
  7. 2/2 t5403: use test_cmp for post-checkout argument checksDeveshi Dwivedi, Jan 11, 2026
  8. 0/2 t5403: improve post-checkout hook testingDeveshi Dwivedi, Jan 12, 2026
  9. 1/2 t5403:introduce check_post_checkout helper functionDeveshi Dwivedi, Jan 12, 2026
  10. Junio C HamanoJan 12, 2026
  11. 2/2 t5403: use test_cmp for post-checkout argument checksDeveshi Dwivedi, Jan 12, 2026
  12. 0/2 t5403: improve post-checkout hook testingDeveshi Dwivedi, Jan 12, 2026
  13. 1/2 t5403:introduce check_post_checkout helper functionDeveshi Dwivedi, Jan 12, 2026
  14. 2/2 t5403: use test_cmp for post-checkout argument checksDeveshi Dwivedi, Jan 12, 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.