3 # Copyright (c) 2007 Carl D. Worth
6 test_description
='git ls-files test (--with-tree).
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.
12 TEST_PASSES_SANITIZE_LEAK
=true
15 test_expect_success
'setup' '
17 # The bug we are exercising requires a fair number of entries
18 # in a sub-directory so that add_index_entry will trigger a
21 echo file >expected &&
25 for m in 0 1 2 3 4 5 6 7 8 9
29 echo file-$num >>expected ||
34 git commit -m "add a bunch of files" &&
36 # We remove them all so that we will have something to add
37 # back with --with-tree and so that we will definitely be
38 # under the realloc size to trigger the bug.
40 git commit -a -m "remove them all" &&
42 # The bug also requires some entry before our directory so that
43 # prune_path will modify the_index.cache
45 mkdir a_directory_that_sorts_before_sub &&
46 >a_directory_that_sorts_before_sub/file &&
52 test_expect_success
'usage' '
53 test_expect_code 128 git ls-files --with-tree=HEAD -u &&
54 test_expect_code 128 git ls-files --with-tree=HEAD -s &&
55 test_expect_code 128 git ls-files --recurse-submodules --with-tree=HEAD
58 test_expect_success
'git ls-files --with-tree should succeed from subdir' '
59 # We have to run from a sub-directory to trigger prune_path
60 # Then we finally get to run our --with-tree test
63 git ls-files --with-tree=HEAD~1 >../output
67 test_expect_success
'git ls-files --with-tree should add entries from named tree.' '
68 test_cmp expected output
71 test_expect_success
'no duplicates in --with-tree output' '
72 git ls-files --with-tree=HEAD >actual &&
73 sort -u actual >expected &&
74 test_cmp expected actual
77 test_expect_success
'setup: output in a conflict' '
78 test_create_repo conflict &&
79 test_commit -C conflict BASE file &&
80 test_commit -C conflict A file foo &&
81 git -C conflict reset --hard BASE &&
82 test_commit -C conflict B file bar
85 test_expect_success
'output in a conflict' '
86 test_must_fail git -C conflict merge A B &&
87 cat >expected <<-\EOF &&
93 git -C conflict ls-files --with-tree=HEAD >actual &&
94 test_cmp expected actual
97 test_expect_success
'output with removed .git/index' '
98 cat >expected <<-\EOF &&
101 rm conflict/.git/index &&
102 git -C conflict ls-files --with-tree=HEAD >actual &&
103 test_cmp expected actual