Skip to content

Commit 7a747f9

Browse files
deveshidwivedigitster
authored andcommitted
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>
1 parent 1954b94 commit 7a747f9

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

t/t5403-post-checkout-hook.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ TEST_PASSES_SANITIZE_LEAK=true
1717
# <flag> indicating whether this was a branch checkout (1) or file checkout (0).
1818
check_post_checkout () {
1919
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"
2222
}
2323

2424
test_expect_success setup '
2525
test_hook --setup post-checkout <<-\EOF &&
26-
echo "$@" >.git/post-checkout.args
26+
echo "old=$1 new=$2 flag=$3" >.git/post-checkout.args
2727
EOF
2828
test_commit one &&
2929
test_commit two &&
@@ -113,7 +113,7 @@ test_rebase --merge
113113
test_expect_success 'post-checkout hook is triggered by clone' '
114114
mkdir -p templates/hooks &&
115115
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"
117117
EOF
118118
git clone --template=templates . clone3 &&
119119
check_post_checkout clone3/.git/post-checkout.args \

0 commit comments

Comments
 (0)