1#!/bin/sh
2
3test_description='test re-include patterns'
4
5. ./test-lib.sh
6
7test_expect_success 'setup' '
8 mkdir -p fooo foo/bar tmp &&
9 touch abc foo/def foo/bar/ghi foo/bar/bar
10'
11
12test_expect_success 'no match, do not enter subdir and waste cycles' '
13 cat >.gitignore <<-\EOF &&
14 /tmp
15 /foo
16 !fooo/bar/bar
17 EOF
18 GIT_TRACE_EXCLUDE="$(pwd)/tmp/trace" git ls-files -o --exclude-standard >tmp/actual &&
19 ! grep "enter .foo/.\$" tmp/trace &&
20 cat >tmp/expected <<-\EOF &&
21 .gitignore
22 abc
23 EOF
24 test_cmp tmp/expected tmp/actual
25'
26
27test_expect_success 'match, excluded by literal pathname pattern' '
28 cat >.gitignore <<-\EOF &&
29 /tmp
30 /fooo
31 /foo
32 !foo/bar/bar
33 EOF
34 cat >fooo/.gitignore <<-\EOF &&
35 !/*
36 EOF git ls-files -o --exclude-standard >tmp/actual &&
37 cat >tmp/expected <<-\EOF &&
38 .gitignore
39 abc
40 foo/bar/bar
41 EOF
42 test_cmp tmp/expected tmp/actual
43'
44
45test_expect_success 'match, excluded by wildcard pathname pattern' '
46 cat >.gitignore <<-\EOF &&
47 /tmp
48 /fooo
49 /fo?
50 !foo/bar/bar
51 EOF
52 git ls-files -o --exclude-standard >tmp/actual &&
53 cat >tmp/expected <<-\EOF &&
54 .gitignore
55 abc
56 foo/bar/bar
57 EOF
58 test_cmp tmp/expected tmp/actual
59'
60
61test_expect_success 'match, excluded by literal basename pattern' '
62 cat >.gitignore <<-\EOF &&
63 /tmp
64 /fooo
65 foo
66 !foo/bar/bar
67 EOF
68 git ls-files -o --exclude-standard >tmp/actual &&
69 cat >tmp/expected <<-\EOF &&
70 .gitignore
71 abc
72 foo/bar/bar
73 EOF
74 test_cmp tmp/expected tmp/actual
75'
76
77test_expect_success 'match, excluded by wildcard basename pattern' '
78 cat >.gitignore <<-\EOF &&
79 /tmp
80 /fooo
81 fo?
82 !foo/bar/bar
83 EOF
84 git ls-files -o --exclude-standard >tmp/actual &&
85 cat >tmp/expected <<-\EOF &&
86 .gitignore
87 abc
88 foo/bar/bar
89 EOF
90 test_cmp tmp/expected tmp/actual
91'
92
93test_expect_success 'match, excluded by literal mustbedir, basename pattern' '
94 cat >.gitignore <<-\EOF &&
95 /tmp
96 /fooo
97 foo/
98 !foo/bar/bar
99 EOF
100 git ls-files -o --exclude-standard >tmp/actual &&
101 cat >tmp/expected <<-\EOF &&
102 .gitignore
103 abc
104 foo/bar/bar
105 EOF
106 test_cmp tmp/expected tmp/actual
107'
108
109test_expect_success 'match, excluded by literal mustbedir, pathname pattern' '
110 cat >.gitignore <<-\EOF &&
111 /tmp
112 /fooo
113 /foo/
114 !foo/bar/bar
115 EOF
116 git ls-files -o --exclude-standard >tmp/actual &&
117 cat >tmp/expected <<-\EOF &&
118 .gitignore
119 abc
120 foo/bar/bar
121 EOF
122 test_cmp tmp/expected tmp/actual
123'
124
125test_expect_success 'prepare for nested negatives' '
126 cat >.git/info/exclude <<-\EOF &&
127 /.gitignore
128 /tmp
129 /foo
130 /abc
131 EOF
132 git ls-files -o --exclude-standard >tmp/actual &&
133 test_must_be_empty tmp/actual &&
134 mkdir -p 1/2/3/4 &&
135 touch 1/f 1/2/f 1/2/3/f 1/2/3/4/f
136'
137
138test_expect_success 'match, literal pathname, nested negatives' '
139 cat >.gitignore <<-\EOF &&
140 /1
141 !1/2
142 1/2/3
143 !1/2/3/4
144 EOF
145 git ls-files -o --exclude-standard >tmp/actual &&
146 cat >tmp/expected <<-\EOF &&
147 1/2/3/4/f
148 1/2/f
149 EOF
150 test_cmp tmp/expected tmp/actual
151'
152
153test_done