{"thread":{"id":"66603","subject":"[PATCH] t1010: add basic tests for mktree --batch","startedAt":"2026-10-20T11:54:43Z","lastAt":"2026-11-11T21:50:11Z","messageCount":4,"participants":["Roger Koranteng via GitGitGadget","Laveesh Bansal","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"555526","messageId":"pull.2270.git.1792497283164.gitgitgadget@gmail.com","threadId":"66603","inReplyTo":null,"subject":"[PATCH] t1010: add basic tests for mktree --batch","fromName":"Roger Koranteng via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2026-10-20T11:54:43Z","receivedAt":"2026-10-20T11:54:43Z","isPatch":true,"sender":{"key":"name:Roger Koranteng","avatar":null},"body":"From: Roger Koranteng <rogerkorantenng@gmail.com>\n\nThe only \"mktree --batch\" test in t1010 is the one checking that it\nsurvives a concurrent repack. Nothing covers basic batch mode, which\nis how the leak fixed in 6272f3bd17 (mktree: plug per-tree leak in\n--batch mode, 2026-08-29) went unnoticed.\n\nAdd a few tests for it. Two trees in one batch should get the same\nIDs as running plain \"mktree\" on each, a trailing blank line should\nnot add an extra tree, -z input should work, and a tree that names a\nmissing object should make mktree die after printing the trees before\nit. While at it, check that a blank line is rejected without --batch.\n\nOne test feeds two blank lines in a row and expects an empty tree in\nbetween. That is what mktree does today, but the documentation says\ntrees are separated by \"a single blank line\", so I am not sure it is\nintended. The test records the current behaviour.\n\nSuggested-by: Jeff King <peff@peff.net>\nSigned-off-by: Roger Koranteng <rogerkorantenng@gmail.com>\n---\n    t1010: add basic tests for mktree --batch\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-2270%2Frogerkorantenng%2Fmktree-batch-tests-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2270/rogerkorantenng/mktree-batch-tests-v1\nPull-Request: https://github.com/gitgitgadget/git/pull/2270\n\n t/t1010-mktree.sh | 73 +++++++++++++++++++++++++++++++++++++++++++++++\n 1 file changed, 73 insertions(+)\n\ndiff --git a/t/t1010-mktree.sh b/t/t1010-mktree.sh\nindex cecba55d45..42f72acabc 100755\n--- a/t/t1010-mktree.sh\n+++ b/t/t1010-mktree.sh\n@@ -117,4 +117,77 @@ test_expect_success PIPE 'mktree --batch survives a concurrent repack retiring a\n \t)\n '\n \n+test_expect_success 'mktree --batch writes one tree per input block' '\n+\t{\n+\t\tcat top &&\n+\t\techo &&\n+\t\tcat top.withsub\n+\t} >input &&\n+\tcat tree tree.withsub >expect &&\n+\tgit mktree --batch <input >actual &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'mktree --batch ignores a trailing blank line' '\n+\t{\n+\t\tcat top &&\n+\t\techo &&\n+\t\tcat top.withsub &&\n+\t\techo\n+\t} >input &&\n+\tcat tree tree.withsub >expect &&\n+\tgit mktree --batch <input >actual &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'mktree --batch: two blank lines give an empty tree' '\n+\t{\n+\t\tcat top &&\n+\t\techo &&\n+\t\techo &&\n+\t\tcat top.withsub\n+\t} >input &&\n+\t{\n+\t\tcat tree &&\n+\t\tgit mktree </dev/null &&\n+\t\tcat tree.withsub\n+\t} >expect &&\n+\tgit mktree --batch <input >actual &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'mktree rejects a blank line without --batch' '\n+\t{\n+\t\tcat top &&\n+\t\techo &&\n+\t\tcat top.withsub\n+\t} >input &&\n+\ttest_must_fail git mktree <input 2>err &&\n+\ttest_grep \"blank line only valid in batch mode\" err\n+'\n+\n+test_expect_success 'mktree --batch -z reads NUL-terminated input' '\n+\t{\n+\t\tgit ls-tree -z $(cat tree) &&\n+\t\tprintf \"\\0\" &&\n+\t\tgit ls-tree -z $(cat tree.withsub)\n+\t} >input &&\n+\tcat tree tree.withsub >expect &&\n+\tgit mktree --batch -z <input >actual &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'mktree --batch stops at a tree with a missing object' '\n+\tmissing=$(test_oid deadbeef) &&\n+\t{\n+\t\tcat top &&\n+\t\techo &&\n+\t\tprintf \"100644 blob %s\\tmissing\\n\" \"$missing\" &&\n+\t\techo &&\n+\t\tcat top.withsub\n+\t} >input &&\n+\ttest_must_fail git mktree --batch <input >actual &&\n+\ttest_cmp tree actual\n+'\n+\n test_done\n\nbase-commit: 47fdf2208c5b94c8cc01c106b8f7c85efb91c926\n-- \ngitgitgadget\n\n"},{"id":"558011","messageId":"20261109231200.55724-1-laveeshb@laveeshbansal.com","threadId":"66603","inReplyTo":"pull.2270.git.1792497283164.gitgitgadget@gmail.com","subject":"Re: [PATCH] t1010: add basic tests for mktree --batch","fromName":"Laveesh Bansal","fromEmail":"laveeshb@laveeshbansal.com","sentAt":"2026-11-09T23:12:00Z","receivedAt":"2026-11-09T23:12:00Z","isPatch":true,"sender":{"key":"laveeshb@laveeshbansal.com","avatar":null},"body":"Roger Koranteng <rogerkorantenng@gmail.com> writes:\n\n> The only \"mktree --batch\" test in t1010 is the one checking that it\n> survives a concurrent repack. Nothing covers basic batch mode, which\n> is how the leak fixed in 6272f3bd17 (mktree: plug per-tree leak in\n> --batch mode, 2026-08-29) went unnoticed.\n>\n> Add a few tests for it. Two trees in one batch should get the same\n> [...]\n\nThanks for adding these.  t1010 passes for me with the patch, also\nunder SANITIZE=leak.  With 6272f3bd17 reverted, tests 10, 11, 12 and 14\neach fail when run on their own, so they do catch that leak.\n\n> One test feeds two blank lines in a row and expects an empty tree in\n> between. That is what mktree does today, but the documentation says\n> trees are separated by \"a single blank line\", so I am not sure it is\n> intended. The test records the current behaviour.\n\nI would keep this test.  The question about the documentation fits\nbetter below the \"---\" than in the commit message.\n\n> +test_expect_success 'mktree --batch stops at a tree with a missing object' '\n> [...]\n> +\ttest_must_fail git mktree --batch <input >actual &&\n> +\ttest_cmp tree actual\n\nCapturing stderr and checking for the \"is unavailable\" message would\nmake sure it died for the expected reason:\n\n\ttest_must_fail git mktree --batch <input >actual 2>err &&\n\ttest_cmp tree actual &&\n\ttest_grep \"object $missing is unavailable\" err\n\nTested-by: Laveesh Bansal <laveeshb@laveeshbansal.com>\n\n"},{"id":"558149","messageId":"pull.2270.v2.git.1794348807240.gitgitgadget@gmail.com","threadId":"66603","inReplyTo":"pull.2270.git.1792497283164.gitgitgadget@gmail.com","subject":"[PATCH v2] t1010: add basic tests for mktree --batch","fromName":"Roger Koranteng via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2026-11-10T22:13:27Z","receivedAt":"2026-11-10T22:13:27Z","isPatch":true,"sender":{"key":"name:Roger Koranteng","avatar":null},"body":"From: Roger Koranteng <rogerkorantenng@gmail.com>\n\nThe only \"mktree --batch\" test in t1010 is the one checking that it\nsurvives a concurrent repack. Nothing covers basic batch mode, which\nis how the leak fixed in 6272f3bd17 (mktree: plug per-tree leak in\n--batch mode, 2026-08-29) went unnoticed.\n\nAdd a few tests for it. Two trees in one batch should get the same\nIDs as running plain \"mktree\" on each, a trailing blank line should\nnot add an extra tree, -z input should work, and a tree that names a\nmissing object should make mktree die after printing the trees before\nit. While at it, check that a blank line is rejected without --batch.\n\nSuggested-by: Jeff King <peff@peff.net>\nTested-by: Laveesh Bansal <laveeshb@laveeshbansal.com>\nSigned-off-by: Roger Koranteng <rogerkorantenng@gmail.com>\n---\n    t1010: add basic tests for mktree --batch\n    \n    v2: check the error message in the missing-object test, and move the\n    blank-line question out of the commit message.\n    \n    One test feeds two blank lines in a row and expects an empty tree in\n    between. That is what mktree does today, but the documentation says\n    trees are separated by \"a single blank line\", so I am not sure it is\n    intended. Is it, or should mktree reject it?\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-2270%2Frogerkorantenng%2Fmktree-batch-tests-v2\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2270/rogerkorantenng/mktree-batch-tests-v2\nPull-Request: https://github.com/gitgitgadget/git/pull/2270\n\nRange-diff vs v1:\n\n 1:  7a928dccb0 ! 1:  40f09c123f t1010: add basic tests for mktree --batch\n     @@ Commit message\n          missing object should make mktree die after printing the trees before\n          it. While at it, check that a blank line is rejected without --batch.\n      \n     -    One test feeds two blank lines in a row and expects an empty tree in\n     -    between. That is what mktree does today, but the documentation says\n     -    trees are separated by \"a single blank line\", so I am not sure it is\n     -    intended. The test records the current behaviour.\n     -\n          Suggested-by: Jeff King <peff@peff.net>\n     +    Tested-by: Laveesh Bansal <laveeshb@laveeshbansal.com>\n          Signed-off-by: Roger Koranteng <rogerkorantenng@gmail.com>\n      \n       ## t/t1010-mktree.sh ##\n     @@ t/t1010-mktree.sh: test_expect_success PIPE 'mktree --batch survives a concurren\n      +\t\techo &&\n      +\t\tcat top.withsub\n      +\t} >input &&\n     -+\ttest_must_fail git mktree --batch <input >actual &&\n     -+\ttest_cmp tree actual\n     ++\ttest_must_fail git mktree --batch <input >actual 2>err &&\n     ++\ttest_cmp tree actual &&\n     ++\ttest_grep \"object $missing is unavailable\" err\n      +'\n      +\n       test_done\n\n\n t/t1010-mktree.sh | 74 +++++++++++++++++++++++++++++++++++++++++++++++\n 1 file changed, 74 insertions(+)\n\ndiff --git a/t/t1010-mktree.sh b/t/t1010-mktree.sh\nindex cecba55d45..bf03b62215 100755\n--- a/t/t1010-mktree.sh\n+++ b/t/t1010-mktree.sh\n@@ -117,4 +117,78 @@ test_expect_success PIPE 'mktree --batch survives a concurrent repack retiring a\n \t)\n '\n \n+test_expect_success 'mktree --batch writes one tree per input block' '\n+\t{\n+\t\tcat top &&\n+\t\techo &&\n+\t\tcat top.withsub\n+\t} >input &&\n+\tcat tree tree.withsub >expect &&\n+\tgit mktree --batch <input >actual &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'mktree --batch ignores a trailing blank line' '\n+\t{\n+\t\tcat top &&\n+\t\techo &&\n+\t\tcat top.withsub &&\n+\t\techo\n+\t} >input &&\n+\tcat tree tree.withsub >expect &&\n+\tgit mktree --batch <input >actual &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'mktree --batch: two blank lines give an empty tree' '\n+\t{\n+\t\tcat top &&\n+\t\techo &&\n+\t\techo &&\n+\t\tcat top.withsub\n+\t} >input &&\n+\t{\n+\t\tcat tree &&\n+\t\tgit mktree </dev/null &&\n+\t\tcat tree.withsub\n+\t} >expect &&\n+\tgit mktree --batch <input >actual &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'mktree rejects a blank line without --batch' '\n+\t{\n+\t\tcat top &&\n+\t\techo &&\n+\t\tcat top.withsub\n+\t} >input &&\n+\ttest_must_fail git mktree <input 2>err &&\n+\ttest_grep \"blank line only valid in batch mode\" err\n+'\n+\n+test_expect_success 'mktree --batch -z reads NUL-terminated input' '\n+\t{\n+\t\tgit ls-tree -z $(cat tree) &&\n+\t\tprintf \"\\0\" &&\n+\t\tgit ls-tree -z $(cat tree.withsub)\n+\t} >input &&\n+\tcat tree tree.withsub >expect &&\n+\tgit mktree --batch -z <input >actual &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'mktree --batch stops at a tree with a missing object' '\n+\tmissing=$(test_oid deadbeef) &&\n+\t{\n+\t\tcat top &&\n+\t\techo &&\n+\t\tprintf \"100644 blob %s\\tmissing\\n\" \"$missing\" &&\n+\t\techo &&\n+\t\tcat top.withsub\n+\t} >input &&\n+\ttest_must_fail git mktree --batch <input >actual 2>err &&\n+\ttest_cmp tree actual &&\n+\ttest_grep \"object $missing is unavailable\" err\n+'\n+\n test_done\n\nbase-commit: 47fdf2208c5b94c8cc01c106b8f7c85efb91c926\n-- \ngitgitgadget\n\n"},{"id":"558250","messageId":"xmqqmrrfm418.fsf@gitster.g","threadId":"66603","inReplyTo":"pull.2270.v2.git.1794348807240.gitgitgadget@gmail.com","subject":"Re: [PATCH v2] t1010: add basic tests for mktree --batch","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-11-11T21:50:11Z","receivedAt":"2026-11-11T21:50:11Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Roger Koranteng via GitGitGadget\" <gitgitgadget@gmail.com> writes:\n\n> From: Roger Koranteng <rogerkorantenng@gmail.com>\n>\n> The only \"mktree --batch\" test in t1010 is the one checking that it\n> survives a concurrent repack. Nothing covers basic batch mode, which\n> is how the leak fixed in 6272f3bd17 (mktree: plug per-tree leak in\n> --batch mode, 2026-08-29) went unnoticed.\n>\n> Add a few tests for it. Two trees in one batch should get the same\n> IDs as running plain \"mktree\" on each, a trailing blank line should\n> not add an extra tree, -z input should work, and a tree that names a\n> missing object should make mktree die after printing the trees before\n> it. While at it, check that a blank line is rejected without --batch.\n>\n> Suggested-by: Jeff King <peff@peff.net>\n> Tested-by: Laveesh Bansal <laveeshb@laveeshbansal.com>\n> Signed-off-by: Roger Koranteng <rogerkorantenng@gmail.com>\n> ---\n\nThanks, for writing and testing.  Queued.\n\n"}]}