Skip to content

Commit 7a928dc

Browse files
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 6272f3b (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>
1 parent 47fdf22 commit 7a928dc

1 file changed

Lines changed: 73 additions & 0 deletions

File tree

‎t/t1010-mktree.sh‎

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,77 @@ test_expect_success PIPE 'mktree --batch survives a concurrent repack retiring a
117117
)
118118
'
119119

120+
test_expect_success 'mktree --batch writes one tree per input block' '
121+
{
122+
cat top &&
123+
echo &&
124+
cat top.withsub
125+
} >input &&
126+
cat tree tree.withsub >expect &&
127+
git mktree --batch <input >actual &&
128+
test_cmp expect actual
129+
'
130+
131+
test_expect_success 'mktree --batch ignores a trailing blank line' '
132+
{
133+
cat top &&
134+
echo &&
135+
cat top.withsub &&
136+
echo
137+
} >input &&
138+
cat tree tree.withsub >expect &&
139+
git mktree --batch <input >actual &&
140+
test_cmp expect actual
141+
'
142+
143+
test_expect_success 'mktree --batch: two blank lines give an empty tree' '
144+
{
145+
cat top &&
146+
echo &&
147+
echo &&
148+
cat top.withsub
149+
} >input &&
150+
{
151+
cat tree &&
152+
git mktree </dev/null &&
153+
cat tree.withsub
154+
} >expect &&
155+
git mktree --batch <input >actual &&
156+
test_cmp expect actual
157+
'
158+
159+
test_expect_success 'mktree rejects a blank line without --batch' '
160+
{
161+
cat top &&
162+
echo &&
163+
cat top.withsub
164+
} >input &&
165+
test_must_fail git mktree <input 2>err &&
166+
test_grep "blank line only valid in batch mode" err
167+
'
168+
169+
test_expect_success 'mktree --batch -z reads NUL-terminated input' '
170+
{
171+
git ls-tree -z $(cat tree) &&
172+
printf "\0" &&
173+
git ls-tree -z $(cat tree.withsub)
174+
} >input &&
175+
cat tree tree.withsub >expect &&
176+
git mktree --batch -z <input >actual &&
177+
test_cmp expect actual
178+
'
179+
180+
test_expect_success 'mktree --batch stops at a tree with a missing object' '
181+
missing=$(test_oid deadbeef) &&
182+
{
183+
cat top &&
184+
echo &&
185+
printf "100644 blob %s\tmissing\n" "$missing" &&
186+
echo &&
187+
cat top.withsub
188+
} >input &&
189+
test_must_fail git mktree --batch <input >actual &&
190+
test_cmp tree actual
191+
'
192+
120193
test_done

0 commit comments

Comments
 (0)