Describe second batch for 1.7.0 in draft release notes
[git/git.git] / t / t3001-ls-files-others-exclude.sh
CommitLineData
f87f9497
JH
1#!/bin/sh
2#
3# Copyright (c) 2005 Junio C Hamano
4#
5
5be60078 6test_description='git ls-files --others --exclude
f87f9497 7
5be60078 8This test runs git ls-files --others and tests --exclude patterns.
f87f9497
JH
9'
10
11. ./test-lib.sh
12
13rm -fr one three
14for dir in . one one/two three
15do
16 mkdir -p $dir &&
1df092d2 17 for i in 1 2 3 4 5 6 7 8
f87f9497
JH
18 do
19 >$dir/a.$i
20 done
21done
dd482eea
FAG
22>"#ignore1"
23>"#ignore2"
24>"#hidden"
f87f9497
JH
25
26cat >expect <<EOF
27a.2
28a.4
29a.5
1df092d2 30a.8
f87f9497
JH
31one/a.3
32one/a.4
33one/a.5
1df092d2
JH
34one/a.7
35one/two/a.2
f87f9497
JH
36one/two/a.3
37one/two/a.5
1df092d2
JH
38one/two/a.7
39one/two/a.8
f87f9497
JH
40three/a.2
41three/a.3
42three/a.4
43three/a.5
1df092d2 44three/a.8
f87f9497
JH
45EOF
46
47echo '.gitignore
dd482eea
FAG
48\#ignore1
49\#ignore2*
50\#hid*n
f87f9497
JH
51output
52expect
53.gitignore
1df092d2
JH
54*.7
55!*.8' >.git/ignore
f87f9497
JH
56
57echo '*.1
1df092d2
JH
58/*.3
59!*.6' >.gitignore
f87f9497 60echo '*.2
1df092d2
JH
61two/*.4
62!*.7
63*.8' >one/.gitignore
64echo '!*.2
65!*.8' >one/two/.gitignore
f87f9497
JH
66
67test_expect_success \
5be60078
JH
68 'git ls-files --others with various exclude options.' \
69 'git ls-files --others \
1df092d2 70 --exclude=\*.6 \
f87f9497
JH
71 --exclude-per-directory=.gitignore \
72 --exclude-from=.git/ignore \
73 >output &&
3af82863 74 test_cmp expect output'
da7bc9b0 75
d317e438 76# Test \r\n (MSDOS-like systems)
0dbc4e89 77printf '*.1\r\n/*.3\r\n!*.6\r\n' >.gitignore
d317e438
AR
78
79test_expect_success \
5be60078
JH
80 'git ls-files --others with \r\n line endings.' \
81 'git ls-files --others \
d317e438
AR
82 --exclude=\*.6 \
83 --exclude-per-directory=.gitignore \
84 --exclude-from=.git/ignore \
85 >output &&
3af82863 86 test_cmp expect output'
d317e438 87
dd482eea 88cat > excludes-file <<\EOF
0ba956d3
JS
89*.[1-8]
90e*
dd482eea 91\#*
0ba956d3
JS
92EOF
93
5be60078 94git config core.excludesFile excludes-file
0ba956d3 95
637efc34 96git status | grep "^# " > output
0ba956d3
JS
97
98cat > expect << EOF
99# .gitignore
100# a.6
101# one/
102# output
103# three/
104EOF
105
0cb0e143 106test_expect_success 'git status honors core.excludesfile' \
82ebb0b6 107 'test_cmp expect output'
0ba956d3 108
d6b8fc30
JH
109test_expect_success 'trailing slash in exclude allows directory match(1)' '
110
111 git ls-files --others --exclude=one/ >output &&
112 if grep "^one/" output
113 then
114 echo Ooops
115 false
116 else
117 : happy
118 fi
119
120'
121
122test_expect_success 'trailing slash in exclude allows directory match (2)' '
123
124 git ls-files --others --exclude=one/two/ >output &&
125 if grep "^one/two/" output
126 then
127 echo Ooops
128 false
129 else
130 : happy
131 fi
132
133'
134
135test_expect_success 'trailing slash in exclude forces directory match (1)' '
136
137 >two
138 git ls-files --others --exclude=two/ >output &&
139 grep "^two" output
140
141'
142
143test_expect_success 'trailing slash in exclude forces directory match (2)' '
144
145 git ls-files --others --exclude=one/a.1/ >output &&
146 grep "^one/a.1" output
147
148'
149
32738edf
MG
150test_expect_success 'negated exclude matches can override previous ones' '
151
152 git ls-files --others --exclude="a.*" --exclude="!a.1" >output &&
153 grep "^a.1" output
154'
155
da7bc9b0 156test_done