* [PATCH] t1010: add basic tests for mktree --batch
@ 2026-10-20 11:54 Roger Koranteng via GitGitGadget
2026-11-09 23:12 ` Laveesh Bansal
2026-11-10 22:13 ` [PATCH v2] " Roger Koranteng via GitGitGadget
0 siblings, 2 replies; 4+ messages in thread
From: Roger Koranteng via GitGitGadget @ 2026-10-20 11:54 UTC (permalink / raw)
To: git
Cc: Jeff King, Elijah Newren, Patrick Steinhardt, Junio C Hamano,
Kaartic Sivaraam, Christian Couder, Siddharth Asthana,
Usman Akinyemi, Roger Koranteng, Roger Koranteng
From: Roger Koranteng <rogerkorantenng@gmail.com>
The only "mktree --batch" test in t1010 is the one checking that it
survives a concurrent repack. Nothing covers basic batch mode, which
is how the leak fixed in 6272f3bd17 (mktree: plug per-tree leak in
--batch mode, 2026-08-29) went unnoticed.
Add a few tests for it. Two trees in one batch should get the same
IDs as running plain "mktree" on each, a trailing blank line should
not add an extra tree, -z input should work, and a tree that names a
missing object should make mktree die after printing the trees before
it. While at it, check that a blank line is rejected without --batch.
One test feeds two blank lines in a row and expects an empty tree in
between. That is what mktree does today, but the documentation says
trees are separated by "a single blank line", so I am not sure it is
intended. The test records the current behaviour.
Suggested-by: Jeff King <peff@peff.net>
Signed-off-by: Roger Koranteng <rogerkorantenng@gmail.com>
---
t1010: add basic tests for mktree --batch
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-2270%2Frogerkorantenng%2Fmktree-batch-tests-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2270/rogerkorantenng/mktree-batch-tests-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/2270
t/t1010-mktree.sh | 73 +++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 73 insertions(+)
diff --git a/t/t1010-mktree.sh b/t/t1010-mktree.sh
index cecba55d45..42f72acabc 100755
--- a/t/t1010-mktree.sh
+++ b/t/t1010-mktree.sh
@@ -117,4 +117,77 @@ test_expect_success PIPE 'mktree --batch survives a concurrent repack retiring a
)
'
+test_expect_success 'mktree --batch writes one tree per input block' '
+ {
+ cat top &&
+ echo &&
+ cat top.withsub
+ } >input &&
+ cat tree tree.withsub >expect &&
+ git mktree --batch <input >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'mktree --batch ignores a trailing blank line' '
+ {
+ cat top &&
+ echo &&
+ cat top.withsub &&
+ echo
+ } >input &&
+ cat tree tree.withsub >expect &&
+ git mktree --batch <input >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'mktree --batch: two blank lines give an empty tree' '
+ {
+ cat top &&
+ echo &&
+ echo &&
+ cat top.withsub
+ } >input &&
+ {
+ cat tree &&
+ git mktree </dev/null &&
+ cat tree.withsub
+ } >expect &&
+ git mktree --batch <input >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'mktree rejects a blank line without --batch' '
+ {
+ cat top &&
+ echo &&
+ cat top.withsub
+ } >input &&
+ test_must_fail git mktree <input 2>err &&
+ test_grep "blank line only valid in batch mode" err
+'
+
+test_expect_success 'mktree --batch -z reads NUL-terminated input' '
+ {
+ git ls-tree -z $(cat tree) &&
+ printf "\0" &&
+ git ls-tree -z $(cat tree.withsub)
+ } >input &&
+ cat tree tree.withsub >expect &&
+ git mktree --batch -z <input >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'mktree --batch stops at a tree with a missing object' '
+ missing=$(test_oid deadbeef) &&
+ {
+ cat top &&
+ echo &&
+ printf "100644 blob %s\tmissing\n" "$missing" &&
+ echo &&
+ cat top.withsub
+ } >input &&
+ test_must_fail git mktree --batch <input >actual &&
+ test_cmp tree actual
+'
+
test_done
base-commit: 47fdf2208c5b94c8cc01c106b8f7c85efb91c926
--
gitgitgadget
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] t1010: add basic tests for mktree --batch
2026-10-20 11:54 [PATCH] t1010: add basic tests for mktree --batch Roger Koranteng via GitGitGadget
@ 2026-11-09 23:12 ` Laveesh Bansal
2026-11-10 22:13 ` [PATCH v2] " Roger Koranteng via GitGitGadget
1 sibling, 0 replies; 4+ messages in thread
From: Laveesh Bansal @ 2026-11-09 23:12 UTC (permalink / raw)
To: Roger Koranteng
Cc: git, Jeff King, Elijah Newren, Patrick Steinhardt, Junio C Hamano
Roger Koranteng <rogerkorantenng@gmail.com> writes:
> The only "mktree --batch" test in t1010 is the one checking that it
> survives a concurrent repack. Nothing covers basic batch mode, which
> is how the leak fixed in 6272f3bd17 (mktree: plug per-tree leak in
> --batch mode, 2026-08-29) went unnoticed.
>
> Add a few tests for it. Two trees in one batch should get the same
> [...]
Thanks for adding these. t1010 passes for me with the patch, also
under SANITIZE=leak. With 6272f3bd17 reverted, tests 10, 11, 12 and 14
each fail when run on their own, so they do catch that leak.
> One test feeds two blank lines in a row and expects an empty tree in
> between. That is what mktree does today, but the documentation says
> trees are separated by "a single blank line", so I am not sure it is
> intended. The test records the current behaviour.
I would keep this test. The question about the documentation fits
better below the "---" than in the commit message.
> +test_expect_success 'mktree --batch stops at a tree with a missing object' '
> [...]
> + test_must_fail git mktree --batch <input >actual &&
> + test_cmp tree actual
Capturing stderr and checking for the "is unavailable" message would
make sure it died for the expected reason:
test_must_fail git mktree --batch <input >actual 2>err &&
test_cmp tree actual &&
test_grep "object $missing is unavailable" err
Tested-by: Laveesh Bansal <laveeshb@laveeshbansal.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2] t1010: add basic tests for mktree --batch
2026-10-20 11:54 [PATCH] t1010: add basic tests for mktree --batch Roger Koranteng via GitGitGadget
2026-11-09 23:12 ` Laveesh Bansal
@ 2026-11-10 22:13 ` Roger Koranteng via GitGitGadget
2026-11-11 21:50 ` Junio C Hamano
1 sibling, 1 reply; 4+ messages in thread
From: Roger Koranteng via GitGitGadget @ 2026-11-10 22:13 UTC (permalink / raw)
To: git
Cc: Jeff King, Elijah Newren, Patrick Steinhardt, Junio C Hamano,
Kaartic Sivaraam, Christian Couder, Siddharth Asthana,
Usman Akinyemi, Laveesh Bansal, Roger Koranteng, Roger Koranteng
From: Roger Koranteng <rogerkorantenng@gmail.com>
The only "mktree --batch" test in t1010 is the one checking that it
survives a concurrent repack. Nothing covers basic batch mode, which
is how the leak fixed in 6272f3bd17 (mktree: plug per-tree leak in
--batch mode, 2026-08-29) went unnoticed.
Add a few tests for it. Two trees in one batch should get the same
IDs as running plain "mktree" on each, a trailing blank line should
not add an extra tree, -z input should work, and a tree that names a
missing object should make mktree die after printing the trees before
it. While at it, check that a blank line is rejected without --batch.
Suggested-by: Jeff King <peff@peff.net>
Tested-by: Laveesh Bansal <laveeshb@laveeshbansal.com>
Signed-off-by: Roger Koranteng <rogerkorantenng@gmail.com>
---
t1010: add basic tests for mktree --batch
v2: check the error message in the missing-object test, and move the
blank-line question out of the commit message.
One test feeds two blank lines in a row and expects an empty tree in
between. That is what mktree does today, but the documentation says
trees are separated by "a single blank line", so I am not sure it is
intended. Is it, or should mktree reject it?
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-2270%2Frogerkorantenng%2Fmktree-batch-tests-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2270/rogerkorantenng/mktree-batch-tests-v2
Pull-Request: https://github.com/gitgitgadget/git/pull/2270
Range-diff vs v1:
1: 7a928dccb0 ! 1: 40f09c123f t1010: add basic tests for mktree --batch
@@ Commit message
missing object should make mktree die after printing the trees before
it. While at it, check that a blank line is rejected without --batch.
- One test feeds two blank lines in a row and expects an empty tree in
- between. That is what mktree does today, but the documentation says
- trees are separated by "a single blank line", so I am not sure it is
- intended. The test records the current behaviour.
-
Suggested-by: Jeff King <peff@peff.net>
+ Tested-by: Laveesh Bansal <laveeshb@laveeshbansal.com>
Signed-off-by: Roger Koranteng <rogerkorantenng@gmail.com>
## t/t1010-mktree.sh ##
@@ t/t1010-mktree.sh: test_expect_success PIPE 'mktree --batch survives a concurren
+ echo &&
+ cat top.withsub
+ } >input &&
-+ test_must_fail git mktree --batch <input >actual &&
-+ test_cmp tree actual
++ test_must_fail git mktree --batch <input >actual 2>err &&
++ test_cmp tree actual &&
++ test_grep "object $missing is unavailable" err
+'
+
test_done
t/t1010-mktree.sh | 74 +++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 74 insertions(+)
diff --git a/t/t1010-mktree.sh b/t/t1010-mktree.sh
index cecba55d45..bf03b62215 100755
--- a/t/t1010-mktree.sh
+++ b/t/t1010-mktree.sh
@@ -117,4 +117,78 @@ test_expect_success PIPE 'mktree --batch survives a concurrent repack retiring a
)
'
+test_expect_success 'mktree --batch writes one tree per input block' '
+ {
+ cat top &&
+ echo &&
+ cat top.withsub
+ } >input &&
+ cat tree tree.withsub >expect &&
+ git mktree --batch <input >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'mktree --batch ignores a trailing blank line' '
+ {
+ cat top &&
+ echo &&
+ cat top.withsub &&
+ echo
+ } >input &&
+ cat tree tree.withsub >expect &&
+ git mktree --batch <input >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'mktree --batch: two blank lines give an empty tree' '
+ {
+ cat top &&
+ echo &&
+ echo &&
+ cat top.withsub
+ } >input &&
+ {
+ cat tree &&
+ git mktree </dev/null &&
+ cat tree.withsub
+ } >expect &&
+ git mktree --batch <input >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'mktree rejects a blank line without --batch' '
+ {
+ cat top &&
+ echo &&
+ cat top.withsub
+ } >input &&
+ test_must_fail git mktree <input 2>err &&
+ test_grep "blank line only valid in batch mode" err
+'
+
+test_expect_success 'mktree --batch -z reads NUL-terminated input' '
+ {
+ git ls-tree -z $(cat tree) &&
+ printf "\0" &&
+ git ls-tree -z $(cat tree.withsub)
+ } >input &&
+ cat tree tree.withsub >expect &&
+ git mktree --batch -z <input >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'mktree --batch stops at a tree with a missing object' '
+ missing=$(test_oid deadbeef) &&
+ {
+ cat top &&
+ echo &&
+ printf "100644 blob %s\tmissing\n" "$missing" &&
+ echo &&
+ cat top.withsub
+ } >input &&
+ test_must_fail git mktree --batch <input >actual 2>err &&
+ test_cmp tree actual &&
+ test_grep "object $missing is unavailable" err
+'
+
test_done
base-commit: 47fdf2208c5b94c8cc01c106b8f7c85efb91c926
--
gitgitgadget
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2] t1010: add basic tests for mktree --batch
2026-11-10 22:13 ` [PATCH v2] " Roger Koranteng via GitGitGadget
@ 2026-11-11 21:50 ` Junio C Hamano
0 siblings, 0 replies; 4+ messages in thread
From: Junio C Hamano @ 2026-11-11 21:50 UTC (permalink / raw)
To: Roger Koranteng via GitGitGadget
Cc: git, Jeff King, Elijah Newren, Patrick Steinhardt,
Kaartic Sivaraam, Christian Couder, Siddharth Asthana,
Usman Akinyemi, Laveesh Bansal, Roger Koranteng
"Roger Koranteng via GitGitGadget" <gitgitgadget@gmail.com> writes:
> From: Roger Koranteng <rogerkorantenng@gmail.com>
>
> The only "mktree --batch" test in t1010 is the one checking that it
> survives a concurrent repack. Nothing covers basic batch mode, which
> is how the leak fixed in 6272f3bd17 (mktree: plug per-tree leak in
> --batch mode, 2026-08-29) went unnoticed.
>
> Add a few tests for it. Two trees in one batch should get the same
> IDs as running plain "mktree" on each, a trailing blank line should
> not add an extra tree, -z input should work, and a tree that names a
> missing object should make mktree die after printing the trees before
> it. While at it, check that a blank line is rejected without --batch.
>
> Suggested-by: Jeff King <peff@peff.net>
> Tested-by: Laveesh Bansal <laveeshb@laveeshbansal.com>
> Signed-off-by: Roger Koranteng <rogerkorantenng@gmail.com>
> ---
Thanks, for writing and testing. Queued.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-11 21:50 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-20 11:54 [PATCH] t1010: add basic tests for mktree --batch Roger Koranteng via GitGitGadget
2026-11-09 23:12 ` Laveesh Bansal
2026-11-10 22:13 ` [PATCH v2] " Roger Koranteng via GitGitGadget
2026-11-11 21:50 ` Junio C Hamano
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox