{"thread":{"id":"64769","subject":"[PATCH 0/2] t5403: improve post-checkout hook testing","startedAt":"2026-01-11T07:30:07Z","lastAt":"2026-01-12T16:36:57Z","messageCount":14,"participants":["Deveshi Dwivedi","Eric Sunshine","Pushkar Singh","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"533517","messageId":"20260111072950.9463-1-deveshigurgaon@gmail.com","threadId":"64769","inReplyTo":null,"subject":"[PATCH 0/2] t5403: improve post-checkout hook testing","fromName":"Deveshi Dwivedi","fromEmail":"deveshigurgaon@gmail.com","sentAt":"2026-01-11T07:29:48Z","receivedAt":"2026-01-11T07:30:07Z","isPatch":true,"sender":{"key":"deveshigurgaon@gmail.com","avatar":"https://avatars.githubusercontent.com/u/120312681?v=4"},"body":"Following up on the recently merged patch that replaced 'test -f' with\ntest_path_is_file, this series continues the cleanup of the\npost-checkout hook tests.\n\nPatch 1/2 introduces a check_post_checkout helper function to replace\nthe repeated pattern of reading and validating hook arguments. This\nrefactoring does not change test behavior, but makes the code easier\nto maintain and prepares it for further improvement.\n\nPatch 2/2 updates the helper and hook output format to use test_cmp\ninstead of individual test commands. This provides clearer error\nmessages on failure, making it easier to see which argument (old ref,\nnew ref, or flag) did not match the expectation.\n\n\nDeveshi Dwivedi (2):\n  t5403:introduce check_post_checkout helper function\n  t5403: use test_cmp for post-checkout argument checks\n\n t/t5403-post-checkout-hook.sh | 49 +++++++++++++++++++----------------\n 1 file changed, 26 insertions(+), 23 deletions(-)\n\n-- \n2.52.0.230.gd8af7cadaa\n\n"},{"id":"533518","messageId":"20260111072950.9463-2-deveshigurgaon@gmail.com","threadId":"64769","inReplyTo":"20260111072950.9463-1-deveshigurgaon@gmail.com","subject":"[PATCH 1/2] t5403:introduce check_post_checkout helper function","fromName":"Deveshi Dwivedi","fromEmail":"deveshigurgaon@gmail.com","sentAt":"2026-01-11T07:29:49Z","receivedAt":"2026-01-11T07:30:11Z","isPatch":true,"sender":{"key":"deveshigurgaon@gmail.com","avatar":"https://avatars.githubusercontent.com/u/120312681?v=4"},"body":"The test file repeatedly uses the same four-line pattern to validate\npost-checkout hook arguments: read the args file, then test each of\nthe three values individually.\n\nIntroduce a check_post_checkout helper function that encapsulates this\npattern. This patch does not change test behavior; it prepares the\ncode for improvement in the next step.\n\nSigned-off-by: Deveshi Dwivedi <deveshigurgaon@gmail.com>\n---\n t/t5403-post-checkout-hook.sh | 45 +++++++++++++++++++----------------\n 1 file changed, 24 insertions(+), 21 deletions(-)\n\ndiff --git a/t/t5403-post-checkout-hook.sh b/t/t5403-post-checkout-hook.sh\nindex 1462e3365b..63a2221441 100755\n--- a/t/t5403-post-checkout-hook.sh\n+++ b/t/t5403-post-checkout-hook.sh\n@@ -9,6 +9,13 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME\n \n . ./test-lib.sh\n \n+# Helper function to check post-checkout hook arguments\n+check_post_checkout () {\n+\ttest \"$#\" = 4 || BUG \"check_post_checkout takes 4 args\"\n+\tread old new flag <\"$1\" &&\n+\ttest \"$old\" = \"$2\" && test \"$new\" = \"$3\" && test \"$flag\" = \"$4\"\n+}\n+\n test_expect_success setup '\n \ttest_hook --setup post-checkout <<-\\EOF &&\n \techo \"$@\" >.git/post-checkout.args\n@@ -23,29 +30,30 @@ test_expect_success setup '\n test_expect_success 'post-checkout receives the right arguments with HEAD unchanged ' '\n \ttest_when_finished \"rm -f .git/post-checkout.args\" &&\n \tgit checkout main &&\n-\tread old new flag <.git/post-checkout.args &&\n-\ttest $old = $new && test $flag = 1\n+\tcheck_post_checkout .git/post-checkout.args \\\n+\t\t\"$(git rev-parse HEAD)\" \"$(git rev-parse HEAD)\" 1\n '\n \n test_expect_success 'post-checkout args are correct with git checkout -b ' '\n \ttest_when_finished \"rm -f .git/post-checkout.args\" &&\n \tgit checkout -b new1 &&\n-\tread old new flag <.git/post-checkout.args &&\n-\ttest $old = $new && test $flag = 1\n+\tcheck_post_checkout .git/post-checkout.args \\\n+\t\t\"$(git rev-parse HEAD)\" \"$(git rev-parse HEAD)\" 1\n '\n \n test_expect_success 'post-checkout receives the right args with HEAD changed ' '\n \ttest_when_finished \"rm -f .git/post-checkout.args\" &&\n+\told=$(git rev-parse HEAD) &&\n \tgit checkout two &&\n-\tread old new flag <.git/post-checkout.args &&\n-\ttest $old != $new && test $flag = 1\n+\tcheck_post_checkout .git/post-checkout.args \\\n+\t\t\"$old\" \"$(git rev-parse HEAD)\" 1\n '\n \n test_expect_success 'post-checkout receives the right args when not switching branches ' '\n \ttest_when_finished \"rm -f .git/post-checkout.args\" &&\n \tgit checkout main -- three.t &&\n-\tread old new flag <.git/post-checkout.args &&\n-\ttest $old = $new && test $flag = 0\n+\tcheck_post_checkout .git/post-checkout.args \\\n+\t\t\"$(git rev-parse HEAD)\" \"$(git rev-parse HEAD)\" 0\n '\n \n test_rebase () {\n@@ -55,10 +63,8 @@ test_rebase () {\n \t\tgit checkout -B rebase-test main &&\n \t\trm -f .git/post-checkout.args &&\n \t\tgit rebase $args rebase-on-me &&\n-\t\tread old new flag <.git/post-checkout.args &&\n-\t\ttest_cmp_rev main $old &&\n-\t\ttest_cmp_rev rebase-on-me $new &&\n-\t\ttest $flag = 1\n+\t\tcheck_post_checkout .git/post-checkout.args \\\n+\t\t\t\"$(git rev-parse main)\" \"$(git rev-parse rebase-on-me)\" 1\n \t'\n \n \ttest_expect_success \"post-checkout is triggered on rebase $args with fast-forward\" '\n@@ -66,10 +72,8 @@ test_rebase () {\n \t\tgit checkout -B ff-rebase-test rebase-on-me^ &&\n \t\trm -f .git/post-checkout.args &&\n \t\tgit rebase $args rebase-on-me &&\n-\t\tread old new flag <.git/post-checkout.args &&\n-\t\ttest_cmp_rev rebase-on-me^ $old &&\n-\t\ttest_cmp_rev rebase-on-me $new &&\n-\t\ttest $flag = 1\n+\t\tcheck_post_checkout .git/post-checkout.args \\\n+\t\t\t\"$(git rev-parse rebase-on-me^)\" \"$(git rev-parse rebase-on-me)\" 1\n \t'\n \n \ttest_expect_success \"rebase $args fast-forward branch checkout runs post-checkout hook\" '\n@@ -79,10 +83,8 @@ test_rebase () {\n \t\tgit checkout two  &&\n \t\trm -f .git/post-checkout.args &&\n \t\tgit rebase $args HEAD rebase-fast-forward  &&\n-\t\tread old new flag <.git/post-checkout.args &&\n-\t\ttest_cmp_rev two $old &&\n-\t\ttest_cmp_rev three $new &&\n-\t\ttest $flag = 1\n+\t\tcheck_post_checkout .git/post-checkout.args \\\n+\t\t\t\"$(git rev-parse two)\" \"$(git rev-parse three)\" 1\n \t'\n \n \ttest_expect_success \"rebase $args checkout does not remove untracked files\" '\n@@ -109,7 +111,8 @@ test_expect_success 'post-checkout hook is triggered by clone' '\n \techo \"$@\" >\"$GIT_DIR/post-checkout.args\"\n \tEOF\n \tgit clone --template=templates . clone3 &&\n-\ttest_path_is_file clone3/.git/post-checkout.args\n+\tcheck_post_checkout clone3/.git/post-checkout.args \\\n+\t\t\"$(test_oid zero)\" \"$(git -C clone3 rev-parse HEAD)\" 1\n '\n \n test_done\n-- \n2.52.0.230.gd8af7cadaa\n\n"},{"id":"533519","messageId":"20260111072950.9463-3-deveshigurgaon@gmail.com","threadId":"64769","inReplyTo":"20260111072950.9463-1-deveshigurgaon@gmail.com","subject":"[PATCH 2/2] t5403: use test_cmp for post-checkout argument checks","fromName":"Deveshi Dwivedi","fromEmail":"deveshigurgaon@gmail.com","sentAt":"2026-01-11T07:29:50Z","receivedAt":"2026-01-11T07:30:15Z","isPatch":true,"sender":{"key":"deveshigurgaon@gmail.com","avatar":"https://avatars.githubusercontent.com/u/120312681?v=4"},"body":"Update check_post_checkout and the post-checkout hook implementation to\nuse test_cmp instead of individual test commands. This provides better\nerror messages when tests fail, making it easier to debug which specific\nargument (old ref, new ref, or flag) was incorrect.\n\nThe hook now outputs in key=value format which test_cmp can display\nclearly when there's a mismatch.\n\nSigned-off-by: Deveshi Dwivedi <deveshigurgaon@gmail.com>\n---\n t/t5403-post-checkout-hook.sh | 8 ++++----\n 1 file changed, 4 insertions(+), 4 deletions(-)\n\ndiff --git a/t/t5403-post-checkout-hook.sh b/t/t5403-post-checkout-hook.sh\nindex 63a2221441..a50c8d0eee 100755\n--- a/t/t5403-post-checkout-hook.sh\n+++ b/t/t5403-post-checkout-hook.sh\n@@ -12,13 +12,13 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME\n # Helper function to check post-checkout hook arguments\n check_post_checkout () {\n \ttest \"$#\" = 4 || BUG \"check_post_checkout takes 4 args\"\n-\tread old new flag <\"$1\" &&\n-\ttest \"$old\" = \"$2\" && test \"$new\" = \"$3\" && test \"$flag\" = \"$4\"\n+\techo \"old=$2 new=$3 flag=$4\" >expect &&\n+\ttest_cmp expect \"$1\"\n }\n \n test_expect_success setup '\n \ttest_hook --setup post-checkout <<-\\EOF &&\n-\techo \"$@\" >.git/post-checkout.args\n+\techo \"old=$1 new=$2 flag=$3\" >.git/post-checkout.args\n \tEOF\n \ttest_commit one &&\n \ttest_commit two &&\n@@ -108,7 +108,7 @@ test_rebase --merge\n test_expect_success 'post-checkout hook is triggered by clone' '\n \tmkdir -p templates/hooks &&\n \twrite_script templates/hooks/post-checkout <<-\\EOF &&\n-\techo \"$@\" >\"$GIT_DIR/post-checkout.args\"\n+\techo \"old=$1 new=$2 flag=$3\" >\"$GIT_DIR/post-checkout.args\"\n \tEOF\n \tgit clone --template=templates . clone3 &&\n \tcheck_post_checkout clone3/.git/post-checkout.args \\\n-- \n2.52.0.230.gd8af7cadaa\n\n"},{"id":"533520","messageId":"CAPig+cQgF2yHL40OnOB=SWMHCv+z0hLTAwTD8q18-DGPHO48cg@mail.gmail.com","threadId":"64769","inReplyTo":"20260111072950.9463-2-deveshigurgaon@gmail.com","subject":"Re: [PATCH 1/2] t5403:introduce check_post_checkout helper function","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2026-01-11T07:53:37Z","receivedAt":"2026-01-11T07:53:54Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Sun, Jan 11, 2026 at 2:30 AM Deveshi Dwivedi\n<deveshigurgaon@gmail.com> wrote:\n> The test file repeatedly uses the same four-line pattern to validate\n> post-checkout hook arguments: read the args file, then test each of\n> the three values individually.\n>\n> Introduce a check_post_checkout helper function that encapsulates this\n> pattern. This patch does not change test behavior; it prepares the\n> code for improvement in the next step.\n>\n> Signed-off-by: Deveshi Dwivedi <deveshigurgaon@gmail.com>\n> ---\n> diff --git a/t/t5403-post-checkout-hook.sh b/t/t5403-post-checkout-hook.sh\n> @@ -9,6 +9,13 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME\n> +# Helper function to check post-checkout hook arguments\n> +check_post_checkout () {\n> +       test \"$#\" = 4 || BUG \"check_post_checkout takes 4 args\"\n> +       read old new flag <\"$1\" &&\n> +       test \"$old\" = \"$2\" && test \"$new\" = \"$3\" && test \"$flag\" = \"$4\"\n> +}\n\nRather than forcing people to read the function body to divine the\npurpose of the four arguments, the function comment should spell out\ntheir meaning. See the many \"Usage:\" comments in\nt/test-lib-functions.sh for examples of how to write more useful\nfunction documentation.\n"},{"id":"533521","messageId":"CALE2CrSHocR-p_zVS8CihtJRpR6Fd72JTy1-KJ7L9iMMubp0sA@mail.gmail.com","threadId":"64769","inReplyTo":"CAPig+cQgF2yHL40OnOB=SWMHCv+z0hLTAwTD8q18-DGPHO48cg@mail.gmail.com","subject":"Re: [PATCH 1/2] t5403:introduce check_post_checkout helper function","fromName":"Pushkar Singh","fromEmail":"pushkarkumarsingh1970@gmail.com","sentAt":"2026-01-11T11:01:39Z","receivedAt":"2026-01-11T11:01:50Z","isPatch":true,"sender":{"key":"pushkarkumarsingh1970@gmail.com","avatar":"https://avatars.githubusercontent.com/u/173247767?v=4"},"body":"I agree with Eric’s point about documenting the helper’s arguments.\n\nSince patch 2 also changes the hook output format to a structured\n\"old=… new=… flag=…\" layout that \"check_post_checkout()\" depends on,\nit would be especially helpful if the function comment spelled out both\nthe meaning of the four parameters and the expected on-disk format of\nthe args file.\n\nThat would make the helper’s contract much clearer to future readers\nand reduce the risk of accidental breakage if the hook output changes.\n\nOn Sun, Jan 11, 2026 at 1:23 PM Eric Sunshine <sunshine@sunshineco.com> wrote:\n>\n> On Sun, Jan 11, 2026 at 2:30 AM Deveshi Dwivedi\n> <deveshigurgaon@gmail.com> wrote:\n> > The test file repeatedly uses the same four-line pattern to validate\n> > post-checkout hook arguments: read the args file, then test each of\n> > the three values individually.\n> >\n> > Introduce a check_post_checkout helper function that encapsulates this\n> > pattern. This patch does not change test behavior; it prepares the\n> > code for improvement in the next step.\n> >\n> > Signed-off-by: Deveshi Dwivedi <deveshigurgaon@gmail.com>\n> > ---\n> > diff --git a/t/t5403-post-checkout-hook.sh b/t/t5403-post-checkout-hook.sh\n> > @@ -9,6 +9,13 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME\n> > +# Helper function to check post-checkout hook arguments\n> > +check_post_checkout () {\n> > +       test \"$#\" = 4 || BUG \"check_post_checkout takes 4 args\"\n> > +       read old new flag <\"$1\" &&\n> > +       test \"$old\" = \"$2\" && test \"$new\" = \"$3\" && test \"$flag\" = \"$4\"\n> > +}\n>\n> Rather than forcing people to read the function body to divine the\n> purpose of the four arguments, the function comment should spell out\n> their meaning. See the many \"Usage:\" comments in\n> t/test-lib-functions.sh for examples of how to write more useful\n> function documentation.\n>\n"},{"id":"533523","messageId":"20260111121218.33935-1-pushkarkumarsingh1970@gmail.com","threadId":"64769","inReplyTo":"20260111072950.9463-2-deveshigurgaon@gmail.com","subject":"[PATCH] t5403: document check_post_checkout helper","fromName":"Pushkar Singh","fromEmail":"pushkarkumarsingh1970@gmail.com","sentAt":"2026-01-11T12:10:07Z","receivedAt":"2026-01-11T12:12:22Z","isPatch":true,"sender":{"key":"pushkarkumarsingh1970@gmail.com","avatar":"https://avatars.githubusercontent.com/u/173247767?v=4"},"body":"---\n t/t5403-post-checkout-hook.sh | 6 +++++-\n 1 file changed, 5 insertions(+), 1 deletion(-)\n\ndiff --git a/t/t5403-post-checkout-hook.sh b/t/t5403-post-checkout-hook.sh\nindex 63a2221441..31ad369b3f 100755\n--- a/t/t5403-post-checkout-hook.sh\n+++ b/t/t5403-post-checkout-hook.sh\n@@ -9,7 +9,11 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME\n \n . ./test-lib.sh\n \n-# Helper function to check post-checkout hook arguments\n+# Usage: check_post_checkout <args-file> <old> <new> <flag>\n+#\n+# Verifies that the post-checkout hook wrote the expected old and new\n+# object IDs and the expected flag (1 for branch switch, 0 otherwise)\n+# into <args-file>.\n check_post_checkout () {\n \ttest \"$#\" = 4 || BUG \"check_post_checkout takes 4 args\"\n \tread old new flag <\"$1\" &&\n-- \n2.43.0\n\n"},{"id":"533553","messageId":"CAG7UgERQNob=JBCurxcS0+Ev09quzYHkTJoaRCvsw7xShHYX2w@mail.gmail.com","threadId":"64769","inReplyTo":"CAPig+cQgF2yHL40OnOB=SWMHCv+z0hLTAwTD8q18-DGPHO48cg@mail.gmail.com","subject":"Re: [PATCH 1/2] t5403:introduce check_post_checkout helper function","fromName":"Deveshi Dwivedi","fromEmail":"deveshigurgaon@gmail.com","sentAt":"2026-01-12T06:44:15Z","receivedAt":"2026-01-12T06:44:30Z","isPatch":true,"sender":{"key":"deveshigurgaon@gmail.com","avatar":"https://avatars.githubusercontent.com/u/120312681?v=4"},"body":"> Rather than forcing people to read the function body to divine the\n> purpose of the four arguments, the function comment should spell out\n> their meaning. See the many \"Usage:\" comments in\n> t/test-lib-functions.sh for examples of how to write more useful\n> function documentation.\nThanks for the suggestion! I agree, I'll send a v2 with better\nfunction documentation.\n"},{"id":"533554","messageId":"20260112065301.1290-1-deveshigurgaon@gmail.com","threadId":"64769","inReplyTo":"20260111072950.9463-1-deveshigurgaon@gmail.com","subject":"[PATCH v2 0/2] t5403: improve post-checkout hook testing","fromName":"Deveshi Dwivedi","fromEmail":"deveshigurgaon@gmail.com","sentAt":"2026-01-12T06:52:59Z","receivedAt":"2026-01-12T06:53:37Z","isPatch":true,"sender":{"key":"deveshigurgaon@gmail.com","avatar":"https://avatars.githubusercontent.com/u/120312681?v=4"},"body":"Following up on the recently merged patch that replaced 'test -f' with\ntest_path_is_file, this series continues the cleanup of the\npost-checkout hook tests.\n\nPatch 1/2 introduces a check_post_checkout helper function to replace\nthe repeated pattern of reading and validating hook arguments. This\nrefactoring does not change test behavior, but makes the code easier\nto maintain and prepares it for further improvement.\n\nPatch 2/2 updates the helper and hook output format to use test_cmp\ninstead of individual test commands. This provides clearer error\nmessages on failure, making it easier to see which argument (old ref,\nnew ref, or flag) did not match the expectation\n\nChanges since v1:\n- Updated the check_post_checkout helper comment to be more descriptive.\n\nDeveshi Dwivedi (2):\n  t5403:introduce check_post_checkout helper function\n  t5403: use test_cmp for post-checkout argument checks\n\n t/t5403-post-checkout-hook.sh | 53 ++++++++++++++++++++---------------\n 1 file changed, 30 insertions(+), 23 deletions(-)\n\n-- \n2.52.0.230.gd8af7cadaa\n\n"},{"id":"533555","messageId":"20260112065301.1290-2-deveshigurgaon@gmail.com","threadId":"64769","inReplyTo":"20260112065301.1290-1-deveshigurgaon@gmail.com","subject":"[PATCH v2 1/2] t5403:introduce check_post_checkout helper function","fromName":"Deveshi Dwivedi","fromEmail":"deveshigurgaon@gmail.com","sentAt":"2026-01-12T06:53:00Z","receivedAt":"2026-01-12T06:53:39Z","isPatch":true,"sender":{"key":"deveshigurgaon@gmail.com","avatar":"https://avatars.githubusercontent.com/u/120312681?v=4"},"body":"The test file repeatedly uses the same four-line pattern to validate\npost-checkout hook arguments: read the args file, then test each of\nthe three values individually.\n\nIntroduce a check_post_checkout helper function that encapsulates this\npattern. This patch does not change test behavior; it prepares the\ncode for improvement in the next step.\n\nSigned-off-by: Deveshi Dwivedi <deveshigurgaon@gmail.com>\n---\n t/t5403-post-checkout-hook.sh | 49 ++++++++++++++++++++---------------\n 1 file changed, 28 insertions(+), 21 deletions(-)\n\ndiff --git a/t/t5403-post-checkout-hook.sh b/t/t5403-post-checkout-hook.sh\nindex 1462e3365b..7bdea25107 100755\n--- a/t/t5403-post-checkout-hook.sh\n+++ b/t/t5403-post-checkout-hook.sh\n@@ -9,6 +9,17 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME\n \n . ./test-lib.sh\n \n+# Usage: check_post_checkout <file> <old-ref> <new-ref> <flag>\n+#\n+# Verify that the post-checkout hook arguments in <file> match the expected\n+# values: <old-ref> for the previous HEAD, <new-ref> for the new HEAD, and\n+# <flag> indicating whether this was a branch checkout (1) or file checkout (0).\n+check_post_checkout () {\n+\ttest \"$#\" = 4 || BUG \"check_post_checkout takes 4 args\"\n+\tread old new flag <\"$1\" &&\n+\ttest \"$old\" = \"$2\" && test \"$new\" = \"$3\" && test \"$flag\" = \"$4\"\n+}\n+\n test_expect_success setup '\n \ttest_hook --setup post-checkout <<-\\EOF &&\n \techo \"$@\" >.git/post-checkout.args\n@@ -23,29 +34,30 @@ test_expect_success setup '\n test_expect_success 'post-checkout receives the right arguments with HEAD unchanged ' '\n \ttest_when_finished \"rm -f .git/post-checkout.args\" &&\n \tgit checkout main &&\n-\tread old new flag <.git/post-checkout.args &&\n-\ttest $old = $new && test $flag = 1\n+\tcheck_post_checkout .git/post-checkout.args \\\n+\t\t\"$(git rev-parse HEAD)\" \"$(git rev-parse HEAD)\" 1\n '\n \n test_expect_success 'post-checkout args are correct with git checkout -b ' '\n \ttest_when_finished \"rm -f .git/post-checkout.args\" &&\n \tgit checkout -b new1 &&\n-\tread old new flag <.git/post-checkout.args &&\n-\ttest $old = $new && test $flag = 1\n+\tcheck_post_checkout .git/post-checkout.args \\\n+\t\t\"$(git rev-parse HEAD)\" \"$(git rev-parse HEAD)\" 1\n '\n \n test_expect_success 'post-checkout receives the right args with HEAD changed ' '\n \ttest_when_finished \"rm -f .git/post-checkout.args\" &&\n+\told=$(git rev-parse HEAD) &&\n \tgit checkout two &&\n-\tread old new flag <.git/post-checkout.args &&\n-\ttest $old != $new && test $flag = 1\n+\tcheck_post_checkout .git/post-checkout.args \\\n+\t\t\"$old\" \"$(git rev-parse HEAD)\" 1\n '\n \n test_expect_success 'post-checkout receives the right args when not switching branches ' '\n \ttest_when_finished \"rm -f .git/post-checkout.args\" &&\n \tgit checkout main -- three.t &&\n-\tread old new flag <.git/post-checkout.args &&\n-\ttest $old = $new && test $flag = 0\n+\tcheck_post_checkout .git/post-checkout.args \\\n+\t\t\"$(git rev-parse HEAD)\" \"$(git rev-parse HEAD)\" 0\n '\n \n test_rebase () {\n@@ -55,10 +67,8 @@ test_rebase () {\n \t\tgit checkout -B rebase-test main &&\n \t\trm -f .git/post-checkout.args &&\n \t\tgit rebase $args rebase-on-me &&\n-\t\tread old new flag <.git/post-checkout.args &&\n-\t\ttest_cmp_rev main $old &&\n-\t\ttest_cmp_rev rebase-on-me $new &&\n-\t\ttest $flag = 1\n+\t\tcheck_post_checkout .git/post-checkout.args \\\n+\t\t\t\"$(git rev-parse main)\" \"$(git rev-parse rebase-on-me)\" 1\n \t'\n \n \ttest_expect_success \"post-checkout is triggered on rebase $args with fast-forward\" '\n@@ -66,10 +76,8 @@ test_rebase () {\n \t\tgit checkout -B ff-rebase-test rebase-on-me^ &&\n \t\trm -f .git/post-checkout.args &&\n \t\tgit rebase $args rebase-on-me &&\n-\t\tread old new flag <.git/post-checkout.args &&\n-\t\ttest_cmp_rev rebase-on-me^ $old &&\n-\t\ttest_cmp_rev rebase-on-me $new &&\n-\t\ttest $flag = 1\n+\t\tcheck_post_checkout .git/post-checkout.args \\\n+\t\t\t\"$(git rev-parse rebase-on-me^)\" \"$(git rev-parse rebase-on-me)\" 1\n \t'\n \n \ttest_expect_success \"rebase $args fast-forward branch checkout runs post-checkout hook\" '\n@@ -79,10 +87,8 @@ test_rebase () {\n \t\tgit checkout two  &&\n \t\trm -f .git/post-checkout.args &&\n \t\tgit rebase $args HEAD rebase-fast-forward  &&\n-\t\tread old new flag <.git/post-checkout.args &&\n-\t\ttest_cmp_rev two $old &&\n-\t\ttest_cmp_rev three $new &&\n-\t\ttest $flag = 1\n+\t\tcheck_post_checkout .git/post-checkout.args \\\n+\t\t\t\"$(git rev-parse two)\" \"$(git rev-parse three)\" 1\n \t'\n \n \ttest_expect_success \"rebase $args checkout does not remove untracked files\" '\n@@ -109,7 +115,8 @@ test_expect_success 'post-checkout hook is triggered by clone' '\n \techo \"$@\" >\"$GIT_DIR/post-checkout.args\"\n \tEOF\n \tgit clone --template=templates . clone3 &&\n-\ttest_path_is_file clone3/.git/post-checkout.args\n+\tcheck_post_checkout clone3/.git/post-checkout.args \\\n+\t\t\"$(test_oid zero)\" \"$(git -C clone3 rev-parse HEAD)\" 1\n '\n \n test_done\n-- \n2.52.0.230.gd8af7cadaa\n\n"},{"id":"533556","messageId":"20260112065301.1290-3-deveshigurgaon@gmail.com","threadId":"64769","inReplyTo":"20260112065301.1290-1-deveshigurgaon@gmail.com","subject":"[PATCH v2 2/2] t5403: use test_cmp for post-checkout argument checks","fromName":"Deveshi Dwivedi","fromEmail":"deveshigurgaon@gmail.com","sentAt":"2026-01-12T06:53:01Z","receivedAt":"2026-01-12T06:53:42Z","isPatch":true,"sender":{"key":"deveshigurgaon@gmail.com","avatar":"https://avatars.githubusercontent.com/u/120312681?v=4"},"body":"Update check_post_checkout and the post-checkout hook implementation to\nuse test_cmp instead of individual test commands. This provides better\nerror messages when tests fail, making it easier to debug which specific\nargument (old ref, new ref, or flag) was incorrect.\n\nThe hook now outputs in key=value format which test_cmp can display\nclearly when there's a mismatch.\n\nSigned-off-by: Deveshi Dwivedi <deveshigurgaon@gmail.com>\n---\n t/t5403-post-checkout-hook.sh | 8 ++++----\n 1 file changed, 4 insertions(+), 4 deletions(-)\n\ndiff --git a/t/t5403-post-checkout-hook.sh b/t/t5403-post-checkout-hook.sh\nindex 7bdea25107..cb0300b2d2 100755\n--- a/t/t5403-post-checkout-hook.sh\n+++ b/t/t5403-post-checkout-hook.sh\n@@ -16,13 +16,13 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME\n # <flag> indicating whether this was a branch checkout (1) or file checkout (0).\n check_post_checkout () {\n \ttest \"$#\" = 4 || BUG \"check_post_checkout takes 4 args\"\n-\tread old new flag <\"$1\" &&\n-\ttest \"$old\" = \"$2\" && test \"$new\" = \"$3\" && test \"$flag\" = \"$4\"\n+\techo \"old=$2 new=$3 flag=$4\" >expect &&\n+\ttest_cmp expect \"$1\"\n }\n \n test_expect_success setup '\n \ttest_hook --setup post-checkout <<-\\EOF &&\n-\techo \"$@\" >.git/post-checkout.args\n+\techo \"old=$1 new=$2 flag=$3\" >.git/post-checkout.args\n \tEOF\n \ttest_commit one &&\n \ttest_commit two &&\n@@ -112,7 +112,7 @@ test_rebase --merge\n test_expect_success 'post-checkout hook is triggered by clone' '\n \tmkdir -p templates/hooks &&\n \twrite_script templates/hooks/post-checkout <<-\\EOF &&\n-\techo \"$@\" >\"$GIT_DIR/post-checkout.args\"\n+\techo \"old=$1 new=$2 flag=$3\" >\"$GIT_DIR/post-checkout.args\"\n \tEOF\n \tgit clone --template=templates . clone3 &&\n \tcheck_post_checkout clone3/.git/post-checkout.args \\\n-- \n2.52.0.230.gd8af7cadaa\n\n"},{"id":"533637","messageId":"xmqq4ioqopjf.fsf@gitster.g","threadId":"64769","inReplyTo":"20260112065301.1290-2-deveshigurgaon@gmail.com","subject":"Re: [PATCH v2 1/2] t5403:introduce check_post_checkout helper function","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-01-12T14:48:20Z","receivedAt":"2026-01-12T14:48:22Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Deveshi Dwivedi <deveshigurgaon@gmail.com> writes:\n\n> The test file repeatedly uses the same four-line pattern to validate\n> post-checkout hook arguments: read the args file, then test each of\n> the three values individually.\n>\n> Introduce a check_post_checkout helper function that encapsulates this\n> pattern. This patch does not change test behavior; it prepares the\n> code for improvement in the next step.\n>\n> Signed-off-by: Deveshi Dwivedi <deveshigurgaon@gmail.com>\n> ---\n>  t/t5403-post-checkout-hook.sh | 49 ++++++++++++++++++++---------------\n>  1 file changed, 28 insertions(+), 21 deletions(-)\n\nOK.\n\n> diff --git a/t/t5403-post-checkout-hook.sh b/t/t5403-post-checkout-hook.sh\n> index 1462e3365b..7bdea25107 100755\n> --- a/t/t5403-post-checkout-hook.sh\n> +++ b/t/t5403-post-checkout-hook.sh\n> ...\n> @@ -109,7 +115,8 @@ test_expect_success 'post-checkout hook is triggered by clone' '\n>  \techo \"$@\" >\"$GIT_DIR/post-checkout.args\"\n>  \tEOF\n>  \tgit clone --template=templates . clone3 &&\n> -\ttest_path_is_file clone3/.git/post-checkout.args\n> +\tcheck_post_checkout clone3/.git/post-checkout.args \\\n> +\t\t\"$(test_oid zero)\" \"$(git -C clone3 rev-parse HEAD)\" 1\n>  '\n\nAll other hunks are as described but this one is slightly different,\nwhich may want a mention in the proposed log message.  We used to\nonly care about the fact that post-checkout hook was executed, but\nnow we check that we invoke the hook with expected parameters.\n\nOther than that, this looks good; so does the next step.\n\nThanks.\n"},{"id":"533658","messageId":"20260112163643.231-1-deveshigurgaon@gmail.com","threadId":"64769","inReplyTo":"20260111072950.9463-1-deveshigurgaon@gmail.com","subject":"[PATCH v3 0/2] t5403: improve post-checkout hook testing","fromName":"Deveshi Dwivedi","fromEmail":"deveshigurgaon@gmail.com","sentAt":"2026-01-12T16:36:41Z","receivedAt":"2026-01-12T16:36:51Z","isPatch":true,"sender":{"key":"deveshigurgaon@gmail.com","avatar":"https://avatars.githubusercontent.com/u/120312681?v=4"},"body":"Following up on the recently merged patch that replaced 'test -f' with\ntest_path_is_file, this series continues the cleanup of the\npost-checkout hook tests.\n\nPatch 1/2 introduces a check_post_checkout helper function to replace\nthe repeated pattern of reading and validating hook arguments. This\nrefactoring does not change test behavior, but makes the code easier\nto maintain and prepares it for further improvement.\n\nPatch 2/2 updates the helper and hook output format to use test_cmp\ninstead of individual test commands. This provides clearer error\nmessages on failure, making it easier to see which argument (old ref,\nnew ref, or flag) did not match the expectation\n\nChanges since v2:\n- Update commit message of patch 1/2 to note that the clone test now\nvalidates post-checkout hook arguments, not just hook execution.\n\n\nDeveshi Dwivedi (2):\n  t5403:introduce check_post_checkout helper function\n  t5403: use test_cmp for post-checkout argument checks\n\n t/t5403-post-checkout-hook.sh | 53 ++++++++++++++++++++---------------\n 1 file changed, 30 insertions(+), 23 deletions(-)\n\n-- \n2.52.0.230.gd8af7cadaa\n\n"},{"id":"533659","messageId":"20260112163643.231-2-deveshigurgaon@gmail.com","threadId":"64769","inReplyTo":"20260112163643.231-1-deveshigurgaon@gmail.com","subject":"[PATCH v3 1/2] t5403:introduce check_post_checkout helper function","fromName":"Deveshi Dwivedi","fromEmail":"deveshigurgaon@gmail.com","sentAt":"2026-01-12T16:36:42Z","receivedAt":"2026-01-12T16:36:54Z","isPatch":true,"sender":{"key":"deveshigurgaon@gmail.com","avatar":"https://avatars.githubusercontent.com/u/120312681?v=4"},"body":"The test file repeatedly uses the same four-line pattern to validate\npost-checkout hook arguments: read the args file, then test each of\nthe three values individually.\n\nIntroduce a check_post_checkout helper function that encapsulates this\npattern. This patch does not change test behavior; it prepares the\ncode for improvement in the next step.\n\nAdditionally, the 'post-checkout hook is triggered by clone' test is\nimproved to validate the hook arguments (old ref, new ref, and flag)\nrather than just checking that the hook file was created.\n\nSigned-off-by: Deveshi Dwivedi <deveshigurgaon@gmail.com>\n---\n t/t5403-post-checkout-hook.sh | 49 ++++++++++++++++++++---------------\n 1 file changed, 28 insertions(+), 21 deletions(-)\n\ndiff --git a/t/t5403-post-checkout-hook.sh b/t/t5403-post-checkout-hook.sh\nindex 1462e3365b..7bdea25107 100755\n--- a/t/t5403-post-checkout-hook.sh\n+++ b/t/t5403-post-checkout-hook.sh\n@@ -9,6 +9,17 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME\n \n . ./test-lib.sh\n \n+# Usage: check_post_checkout <file> <old-ref> <new-ref> <flag>\n+#\n+# Verify that the post-checkout hook arguments in <file> match the expected\n+# values: <old-ref> for the previous HEAD, <new-ref> for the new HEAD, and\n+# <flag> indicating whether this was a branch checkout (1) or file checkout (0).\n+check_post_checkout () {\n+\ttest \"$#\" = 4 || BUG \"check_post_checkout takes 4 args\"\n+\tread old new flag <\"$1\" &&\n+\ttest \"$old\" = \"$2\" && test \"$new\" = \"$3\" && test \"$flag\" = \"$4\"\n+}\n+\n test_expect_success setup '\n \ttest_hook --setup post-checkout <<-\\EOF &&\n \techo \"$@\" >.git/post-checkout.args\n@@ -23,29 +34,30 @@ test_expect_success setup '\n test_expect_success 'post-checkout receives the right arguments with HEAD unchanged ' '\n \ttest_when_finished \"rm -f .git/post-checkout.args\" &&\n \tgit checkout main &&\n-\tread old new flag <.git/post-checkout.args &&\n-\ttest $old = $new && test $flag = 1\n+\tcheck_post_checkout .git/post-checkout.args \\\n+\t\t\"$(git rev-parse HEAD)\" \"$(git rev-parse HEAD)\" 1\n '\n \n test_expect_success 'post-checkout args are correct with git checkout -b ' '\n \ttest_when_finished \"rm -f .git/post-checkout.args\" &&\n \tgit checkout -b new1 &&\n-\tread old new flag <.git/post-checkout.args &&\n-\ttest $old = $new && test $flag = 1\n+\tcheck_post_checkout .git/post-checkout.args \\\n+\t\t\"$(git rev-parse HEAD)\" \"$(git rev-parse HEAD)\" 1\n '\n \n test_expect_success 'post-checkout receives the right args with HEAD changed ' '\n \ttest_when_finished \"rm -f .git/post-checkout.args\" &&\n+\told=$(git rev-parse HEAD) &&\n \tgit checkout two &&\n-\tread old new flag <.git/post-checkout.args &&\n-\ttest $old != $new && test $flag = 1\n+\tcheck_post_checkout .git/post-checkout.args \\\n+\t\t\"$old\" \"$(git rev-parse HEAD)\" 1\n '\n \n test_expect_success 'post-checkout receives the right args when not switching branches ' '\n \ttest_when_finished \"rm -f .git/post-checkout.args\" &&\n \tgit checkout main -- three.t &&\n-\tread old new flag <.git/post-checkout.args &&\n-\ttest $old = $new && test $flag = 0\n+\tcheck_post_checkout .git/post-checkout.args \\\n+\t\t\"$(git rev-parse HEAD)\" \"$(git rev-parse HEAD)\" 0\n '\n \n test_rebase () {\n@@ -55,10 +67,8 @@ test_rebase () {\n \t\tgit checkout -B rebase-test main &&\n \t\trm -f .git/post-checkout.args &&\n \t\tgit rebase $args rebase-on-me &&\n-\t\tread old new flag <.git/post-checkout.args &&\n-\t\ttest_cmp_rev main $old &&\n-\t\ttest_cmp_rev rebase-on-me $new &&\n-\t\ttest $flag = 1\n+\t\tcheck_post_checkout .git/post-checkout.args \\\n+\t\t\t\"$(git rev-parse main)\" \"$(git rev-parse rebase-on-me)\" 1\n \t'\n \n \ttest_expect_success \"post-checkout is triggered on rebase $args with fast-forward\" '\n@@ -66,10 +76,8 @@ test_rebase () {\n \t\tgit checkout -B ff-rebase-test rebase-on-me^ &&\n \t\trm -f .git/post-checkout.args &&\n \t\tgit rebase $args rebase-on-me &&\n-\t\tread old new flag <.git/post-checkout.args &&\n-\t\ttest_cmp_rev rebase-on-me^ $old &&\n-\t\ttest_cmp_rev rebase-on-me $new &&\n-\t\ttest $flag = 1\n+\t\tcheck_post_checkout .git/post-checkout.args \\\n+\t\t\t\"$(git rev-parse rebase-on-me^)\" \"$(git rev-parse rebase-on-me)\" 1\n \t'\n \n \ttest_expect_success \"rebase $args fast-forward branch checkout runs post-checkout hook\" '\n@@ -79,10 +87,8 @@ test_rebase () {\n \t\tgit checkout two  &&\n \t\trm -f .git/post-checkout.args &&\n \t\tgit rebase $args HEAD rebase-fast-forward  &&\n-\t\tread old new flag <.git/post-checkout.args &&\n-\t\ttest_cmp_rev two $old &&\n-\t\ttest_cmp_rev three $new &&\n-\t\ttest $flag = 1\n+\t\tcheck_post_checkout .git/post-checkout.args \\\n+\t\t\t\"$(git rev-parse two)\" \"$(git rev-parse three)\" 1\n \t'\n \n \ttest_expect_success \"rebase $args checkout does not remove untracked files\" '\n@@ -109,7 +115,8 @@ test_expect_success 'post-checkout hook is triggered by clone' '\n \techo \"$@\" >\"$GIT_DIR/post-checkout.args\"\n \tEOF\n \tgit clone --template=templates . clone3 &&\n-\ttest_path_is_file clone3/.git/post-checkout.args\n+\tcheck_post_checkout clone3/.git/post-checkout.args \\\n+\t\t\"$(test_oid zero)\" \"$(git -C clone3 rev-parse HEAD)\" 1\n '\n \n test_done\n-- \n2.52.0.230.gd8af7cadaa\n\n"},{"id":"533660","messageId":"20260112163643.231-3-deveshigurgaon@gmail.com","threadId":"64769","inReplyTo":"20260112163643.231-1-deveshigurgaon@gmail.com","subject":"[PATCH v3 2/2] t5403: use test_cmp for post-checkout argument checks","fromName":"Deveshi Dwivedi","fromEmail":"deveshigurgaon@gmail.com","sentAt":"2026-01-12T16:36:43Z","receivedAt":"2026-01-12T16:36:57Z","isPatch":true,"sender":{"key":"deveshigurgaon@gmail.com","avatar":"https://avatars.githubusercontent.com/u/120312681?v=4"},"body":"Update check_post_checkout and the post-checkout hook implementation to\nuse test_cmp instead of individual test commands. This provides better\nerror messages when tests fail, making it easier to debug which specific\nargument (old ref, new ref, or flag) was incorrect.\n\nThe hook now outputs in key=value format which test_cmp can display\nclearly when there's a mismatch.\n\nSigned-off-by: Deveshi Dwivedi <deveshigurgaon@gmail.com>\n---\n t/t5403-post-checkout-hook.sh | 8 ++++----\n 1 file changed, 4 insertions(+), 4 deletions(-)\n\ndiff --git a/t/t5403-post-checkout-hook.sh b/t/t5403-post-checkout-hook.sh\nindex 7bdea25107..cb0300b2d2 100755\n--- a/t/t5403-post-checkout-hook.sh\n+++ b/t/t5403-post-checkout-hook.sh\n@@ -16,13 +16,13 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME\n # <flag> indicating whether this was a branch checkout (1) or file checkout (0).\n check_post_checkout () {\n \ttest \"$#\" = 4 || BUG \"check_post_checkout takes 4 args\"\n-\tread old new flag <\"$1\" &&\n-\ttest \"$old\" = \"$2\" && test \"$new\" = \"$3\" && test \"$flag\" = \"$4\"\n+\techo \"old=$2 new=$3 flag=$4\" >expect &&\n+\ttest_cmp expect \"$1\"\n }\n \n test_expect_success setup '\n \ttest_hook --setup post-checkout <<-\\EOF &&\n-\techo \"$@\" >.git/post-checkout.args\n+\techo \"old=$1 new=$2 flag=$3\" >.git/post-checkout.args\n \tEOF\n \ttest_commit one &&\n \ttest_commit two &&\n@@ -112,7 +112,7 @@ test_rebase --merge\n test_expect_success 'post-checkout hook is triggered by clone' '\n \tmkdir -p templates/hooks &&\n \twrite_script templates/hooks/post-checkout <<-\\EOF &&\n-\techo \"$@\" >\"$GIT_DIR/post-checkout.args\"\n+\techo \"old=$1 new=$2 flag=$3\" >\"$GIT_DIR/post-checkout.args\"\n \tEOF\n \tgit clone --template=templates . clone3 &&\n \tcheck_post_checkout clone3/.git/post-checkout.args \\\n-- \n2.52.0.230.gd8af7cadaa\n\n"}]}