]> git.ipfire.org Git - thirdparty/git.git/commitdiff
t5403: use test_cmp for post-checkout argument checks
authorDeveshi Dwivedi <deveshigurgaon@gmail.com>
Mon, 12 Jan 2026 16:36:43 +0000 (16:36 +0000)
committerJunio C Hamano <gitster@pobox.com>
Mon, 12 Jan 2026 19:58:27 +0000 (11:58 -0800)
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>
t/t5403-post-checkout-hook.sh

index d9de4e75297af9ec2b94812d0fdeb1d68d4a4a77..53d97df070ffc1c284cb961677b47869349971a7 100755 (executable)
@@ -17,13 +17,13 @@ TEST_PASSES_SANITIZE_LEAK=true
 # <flag> indicating whether this was a branch checkout (1) or file checkout (0).
 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 &&
@@ -113,7 +113,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 \