From 7a928dccb0d77fc48606dfafa71eb8df4ead2171 Mon Sep 17 00:00:00 2001 From: Roger Koranteng Date: Tue, 20 Oct 2026 10:05:21 +0000 Subject: [PATCH] t1010: add basic tests for mktree --batch 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 Signed-off-by: Roger Koranteng --- t/t1010-mktree.sh | 73 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/t/t1010-mktree.sh b/t/t1010-mktree.sh index cecba55d451f2d..42f72acabc3268 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 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 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 expect && + git mktree --batch 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 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 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 actual && + test_cmp tree actual +' + test_done