]> git.ipfire.org Git - thirdparty/git.git/blame - t/t3001-ls-files-others-exclude.sh
git-commit.txt: Add missing long/short options
[thirdparty/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
22
23cat >expect <<EOF
24a.2
25a.4
26a.5
1df092d2 27a.8
f87f9497
JH
28one/a.3
29one/a.4
30one/a.5
1df092d2
JH
31one/a.7
32one/two/a.2
f87f9497
JH
33one/two/a.3
34one/two/a.5
1df092d2
JH
35one/two/a.7
36one/two/a.8
f87f9497
JH
37three/a.2
38three/a.3
39three/a.4
40three/a.5
1df092d2 41three/a.8
f87f9497
JH
42EOF
43
44echo '.gitignore
45output
46expect
47.gitignore
1df092d2
JH
48*.7
49!*.8' >.git/ignore
f87f9497
JH
50
51echo '*.1
1df092d2
JH
52/*.3
53!*.6' >.gitignore
f87f9497 54echo '*.2
1df092d2
JH
55two/*.4
56!*.7
57*.8' >one/.gitignore
58echo '!*.2
59!*.8' >one/two/.gitignore
f87f9497
JH
60
61test_expect_success \
5be60078
JH
62 'git ls-files --others with various exclude options.' \
63 'git ls-files --others \
1df092d2 64 --exclude=\*.6 \
f87f9497
JH
65 --exclude-per-directory=.gitignore \
66 --exclude-from=.git/ignore \
67 >output &&
3af82863 68 test_cmp expect output'
da7bc9b0 69
d317e438 70# Test \r\n (MSDOS-like systems)
0dbc4e89 71printf '*.1\r\n/*.3\r\n!*.6\r\n' >.gitignore
d317e438
AR
72
73test_expect_success \
5be60078
JH
74 'git ls-files --others with \r\n line endings.' \
75 'git ls-files --others \
d317e438
AR
76 --exclude=\*.6 \
77 --exclude-per-directory=.gitignore \
78 --exclude-from=.git/ignore \
79 >output &&
3af82863 80 test_cmp expect output'
d317e438 81
0ba956d3
JS
82cat > excludes-file << EOF
83*.[1-8]
84e*
85EOF
86
5be60078 87git config core.excludesFile excludes-file
0ba956d3 88
637efc34 89git status | grep "^# " > output
0ba956d3
JS
90
91cat > expect << EOF
92# .gitignore
93# a.6
94# one/
95# output
96# three/
97EOF
98
99test_expect_success 'git-status honours core.excludesfile' \
82ebb0b6 100 'test_cmp expect output'
0ba956d3 101
d6b8fc30
JH
102test_expect_success 'trailing slash in exclude allows directory match(1)' '
103
104 git ls-files --others --exclude=one/ >output &&
105 if grep "^one/" output
106 then
107 echo Ooops
108 false
109 else
110 : happy
111 fi
112
113'
114
115test_expect_success 'trailing slash in exclude allows directory match (2)' '
116
117 git ls-files --others --exclude=one/two/ >output &&
118 if grep "^one/two/" output
119 then
120 echo Ooops
121 false
122 else
123 : happy
124 fi
125
126'
127
128test_expect_success 'trailing slash in exclude forces directory match (1)' '
129
130 >two
131 git ls-files --others --exclude=two/ >output &&
132 grep "^two" output
133
134'
135
136test_expect_success 'trailing slash in exclude forces directory match (2)' '
137
138 git ls-files --others --exclude=one/a.1/ >output &&
139 grep "^one/a.1" output
140
141'
142
da7bc9b0 143test_done