t5403: use test_cmp for post-checkout argument checks
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> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Deveshi Dwivedi committed
Jan 12, 2026 at 16:36 UTC
7a747f972d73d9419603d8127514cf188ed7a9ab
1 file changed
+4
-4
t/t5403-post-checkout-hook.sh
+4
-4
@@ -17,13 +17,13 @@ TEST_PASSES_SANITIZE_LEAK=true
17
# <flag> indicating whether this was a branch checkout (1) or file checkout (0).
18
check_post_checkout () {
19
test "$#" = 4 || BUG "check_post_checkout takes 4 args"
20
- read old new flag <"$1" &&
21
- test "$old" = "$2" && test "$new" = "$3" && test "$flag" = "$4"
20
+ echo "old=$2 new=$3 flag=$4" >expect &&
21
+ test_cmp expect "$1"
22
}
23
24
test_expect_success setup '
25
test_hook --setup post-checkout <<-\EOF &&
26
- echo "$@" >.git/post-checkout.args
26
+ echo "old=$1 new=$2 flag=$3" >.git/post-checkout.args
27
EOF
28
test_commit one &&
29
test_commit two &&
@@ -113,7 +113,7 @@ test_rebase --merge
113
test_expect_success 'post-checkout hook is triggered by clone' '
114
mkdir -p templates/hooks &&
115
write_script templates/hooks/post-checkout <<-\EOF &&
116
- echo "$@" >"$GIT_DIR/post-checkout.args"
116
+ echo "old=$1 new=$2 flag=$3" >"$GIT_DIR/post-checkout.args"
117
EOF
118
git clone --template=templates . clone3 &&
119
check_post_checkout clone3/.git/post-checkout.args \