]>
Commit | Line | Data |
---|---|---|
54e1abce CW |
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 | ||
18337d40 | 13 | test_expect_success 'setup' ' |
54e1abce CW |
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 && | |
54e1abce CW |
21 | for n in 0 1 2 3 4 5 |
22 | do | |
23 | for m in 0 1 2 3 4 5 6 7 8 9 | |
24 | do | |
25 | num=00$n$m && | |
26 | >sub/file-$num && | |
c6587bdd JK |
27 | echo file-$num >>expected || |
28 | return 1 | |
29 | done | |
30 | done && | |
54e1abce CW |
31 | git add . && |
32 | git commit -m "add a bunch of files" && | |
33 | ||
34 | # We remove them all so that we will have something to add | |
35 | # back with --with-tree and so that we will definitely be | |
36 | # under the realloc size to trigger the bug. | |
37 | rm -rf sub && | |
38 | git commit -a -m "remove them all" && | |
39 | ||
40 | # The bug also requires some entry before our directory so that | |
41 | # prune_path will modify the_index.cache | |
42 | ||
43 | mkdir a_directory_that_sorts_before_sub && | |
44 | >a_directory_that_sorts_before_sub/file && | |
45 | mkdir sub && | |
46 | >sub/file && | |
47 | git add . | |
48 | ' | |
49 | ||
8de78218 ÆAB |
50 | test_expect_success 'usage' ' |
51 | test_expect_code 128 git ls-files --with-tree=HEAD -u && | |
52 | test_expect_code 128 git ls-files --with-tree=HEAD -s && | |
53 | test_expect_code 128 git ls-files --recurse-submodules --with-tree=HEAD | |
54 | ' | |
55 | ||
14c4776d | 56 | test_expect_success 'git ls-files --with-tree should succeed from subdir' ' |
18a82692 JN |
57 | # We have to run from a sub-directory to trigger prune_path |
58 | # Then we finally get to run our --with-tree test | |
59 | ( | |
60 | cd sub && | |
61 | git ls-files --with-tree=HEAD~1 >../output | |
62 | ) | |
54e1abce CW |
63 | ' |
64 | ||
18337d40 LL |
65 | test_expect_success 'git ls-files --with-tree should add entries from named tree.' ' |
66 | test_cmp expected output | |
67 | ' | |
54e1abce | 68 | |
8de78218 ÆAB |
69 | test_expect_success 'no duplicates in --with-tree output' ' |
70 | git ls-files --with-tree=HEAD >actual && | |
71 | sort -u actual >expected && | |
72 | test_cmp expected actual | |
73 | ' | |
74 | ||
75 | test_expect_success 'setup: output in a conflict' ' | |
76 | test_create_repo conflict && | |
77 | test_commit -C conflict BASE file && | |
78 | test_commit -C conflict A file foo && | |
79 | git -C conflict reset --hard BASE && | |
80 | test_commit -C conflict B file bar | |
81 | ' | |
82 | ||
83 | test_expect_success 'output in a conflict' ' | |
84 | test_must_fail git -C conflict merge A B && | |
85 | cat >expected <<-\EOF && | |
86 | file | |
87 | file | |
88 | file | |
89 | file | |
90 | EOF | |
91 | git -C conflict ls-files --with-tree=HEAD >actual && | |
92 | test_cmp expected actual | |
93 | ' | |
94 | ||
95 | test_expect_success 'output with removed .git/index' ' | |
96 | cat >expected <<-\EOF && | |
97 | file | |
98 | EOF | |
99 | rm conflict/.git/index && | |
100 | git -C conflict ls-files --with-tree=HEAD >actual && | |
101 | test_cmp expected actual | |
102 | ' | |
103 | ||
54e1abce | 104 | test_done |