Code

add: allow configurations to be overriden by command line
[git.git] / t / t3001-ls-files-others-exclude.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2005 Junio C Hamano
4 #
6 test_description='git ls-files --others --exclude
8 This test runs git ls-files --others and tests --exclude patterns.
9 '
11 . ./test-lib.sh
13 rm -fr one three
14 for dir in . one one/two three
15 do
16   mkdir -p $dir &&
17   for i in 1 2 3 4 5 6 7 8
18   do
19     >$dir/a.$i
20   done
21 done
22 >"#ignore1"
23 >"#ignore2"
24 >"#hidden"
26 cat >expect <<EOF
27 a.2
28 a.4
29 a.5
30 a.8
31 one/a.3
32 one/a.4
33 one/a.5
34 one/a.7
35 one/two/a.2
36 one/two/a.3
37 one/two/a.5
38 one/two/a.7
39 one/two/a.8
40 three/a.2
41 three/a.3
42 three/a.4
43 three/a.5
44 three/a.8
45 EOF
47 echo '.gitignore
48 \#ignore1
49 \#ignore2*
50 \#hid*n
51 output
52 expect
53 .gitignore
54 *.7
55 !*.8' >.git/ignore
57 echo '*.1
58 /*.3
59 !*.6' >.gitignore
60 echo '*.2
61 two/*.4
62 !*.7
63 *.8' >one/.gitignore
64 echo '!*.2
65 !*.8' >one/two/.gitignore
67 test_expect_success \
68     'git ls-files --others with various exclude options.' \
69     'git ls-files --others \
70        --exclude=\*.6 \
71        --exclude-per-directory=.gitignore \
72        --exclude-from=.git/ignore \
73        >output &&
74      test_cmp expect output'
76 # Test \r\n (MSDOS-like systems)
77 printf '*.1\r\n/*.3\r\n!*.6\r\n' >.gitignore
79 test_expect_success \
80     'git ls-files --others with \r\n line endings.' \
81     'git ls-files --others \
82        --exclude=\*.6 \
83        --exclude-per-directory=.gitignore \
84        --exclude-from=.git/ignore \
85        >output &&
86      test_cmp expect output'
88 cat > excludes-file <<\EOF
89 *.[1-8]
90 e*
91 \#*
92 EOF
94 git config core.excludesFile excludes-file
96 git status | grep "^#   " > output
98 cat > expect << EOF
99 #       .gitignore
100 #       a.6
101 #       one/
102 #       output
103 #       three/
104 EOF
106 test_expect_success 'git status honors core.excludesfile' \
107         'test_cmp expect output'
109 test_expect_success 'trailing slash in exclude allows directory match(1)' '
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
122 test_expect_success 'trailing slash in exclude allows directory match (2)' '
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
135 test_expect_success 'trailing slash in exclude forces directory match (1)' '
137         >two
138         git ls-files --others --exclude=two/ >output &&
139         grep "^two" output
143 test_expect_success 'trailing slash in exclude forces directory match (2)' '
145         git ls-files --others --exclude=one/a.1/ >output &&
146         grep "^one/a.1" output
150 test_done