Skip to content

Commit 54e1abc

Browse files
cworth-ghgitster
authored andcommitted
Add test case for ls-files --with-tree
This tests basic functionality and also exercises a bug noticed by Keith Packard, (prune_cache followed by add_index_entry can trigger an attempt to realloc a pointer into the middle of an allocated buffer). Signed-off-by: Junio C Hamano <[email protected]>
1 parent 95af39f commit 54e1abc

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

t/t3060-ls-files-with-tree.sh

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/bin/sh
2+
#
3+
# Copyright (c) 2007 Carl D. Worth
4+
#
5+
6+
test_description='git ls-files test (--with-tree).
7+
8+
This test runs git ls-files --with-tree and in particular in
9+
a scenario known to trigger a crash with some versions of git.
10+
'
11+
. ./test-lib.sh
12+
13+
test_expect_success setup '
14+
15+
# The bug we are exercising requires a fair number of entries
16+
# in a sub-directory so that add_index_entry will trigger a
17+
# realloc.
18+
19+
echo file >expected &&
20+
mkdir sub &&
21+
bad= &&
22+
for n in 0 1 2 3 4 5
23+
do
24+
for m in 0 1 2 3 4 5 6 7 8 9
25+
do
26+
num=00$n$m &&
27+
>sub/file-$num &&
28+
echo file-$num >>expected || {
29+
bad=t
30+
break
31+
}
32+
done && test -z "$bad" || {
33+
bad=t
34+
break
35+
}
36+
done && test -z "$bad" &&
37+
git add . &&
38+
git commit -m "add a bunch of files" &&
39+
40+
# We remove them all so that we will have something to add
41+
# back with --with-tree and so that we will definitely be
42+
# under the realloc size to trigger the bug.
43+
rm -rf sub &&
44+
git commit -a -m "remove them all" &&
45+
46+
# The bug also requires some entry before our directory so that
47+
# prune_path will modify the_index.cache
48+
49+
mkdir a_directory_that_sorts_before_sub &&
50+
>a_directory_that_sorts_before_sub/file &&
51+
mkdir sub &&
52+
>sub/file &&
53+
git add .
54+
'
55+
56+
# We have to run from a sub-directory to trigger prune_path
57+
# Then we finally get to run our --with-tree test
58+
cd sub
59+
60+
test_expect_success 'git -ls-files --with-tree should succeed from subdir' '
61+
62+
git ls-files --with-tree=HEAD~1 >../output
63+
64+
'
65+
66+
cd ..
67+
test_expect_success \
68+
'git -ls-files --with-tree should add entries from named tree.' \
69+
'diff -u expected output'
70+
71+
test_done

0 commit comments

Comments
 (0)