blob: 55f057cebeb37a8ba8cd9c1e6aa5101c66988bcb [file] [log] [blame]
Junio C Hamanof87f9492005-07-24 15:26:09 -07001#!/bin/sh
2#
3# Copyright (c) 2005 Junio C Hamano
4#
5
Junio C Hamano5be60072007-07-02 22:52:14 -07006test_description='git ls-files --others --exclude
Junio C Hamanof87f9492005-07-24 15:26:09 -07007
Junio C Hamano5be60072007-07-02 22:52:14 -07008This test runs git ls-files --others and tests --exclude patterns.
Junio C Hamanof87f9492005-07-24 15:26:09 -07009'
10
11. ./test-lib.sh
12
13rm -fr one three
14for dir in . one one/two three
15do
16 mkdir -p $dir &&
Junio C Hamano1df092d2005-07-28 23:53:29 -070017 for i in 1 2 3 4 5 6 7 8
Junio C Hamanof87f9492005-07-24 15:26:09 -070018 do
19 >$dir/a.$i
20 done
21done
22
23cat >expect <<EOF
24a.2
25a.4
26a.5
Junio C Hamano1df092d2005-07-28 23:53:29 -070027a.8
Junio C Hamanof87f9492005-07-24 15:26:09 -070028one/a.3
29one/a.4
30one/a.5
Junio C Hamano1df092d2005-07-28 23:53:29 -070031one/a.7
32one/two/a.2
Junio C Hamanof87f9492005-07-24 15:26:09 -070033one/two/a.3
34one/two/a.5
Junio C Hamano1df092d2005-07-28 23:53:29 -070035one/two/a.7
36one/two/a.8
Junio C Hamanof87f9492005-07-24 15:26:09 -070037three/a.2
38three/a.3
39three/a.4
40three/a.5
Junio C Hamano1df092d2005-07-28 23:53:29 -070041three/a.8
Junio C Hamanof87f9492005-07-24 15:26:09 -070042EOF
43
44echo '.gitignore
45output
46expect
47.gitignore
Junio C Hamano1df092d2005-07-28 23:53:29 -070048*.7
49!*.8' >.git/ignore
Junio C Hamanof87f9492005-07-24 15:26:09 -070050
51echo '*.1
Junio C Hamano1df092d2005-07-28 23:53:29 -070052/*.3
53!*.6' >.gitignore
Junio C Hamanof87f9492005-07-24 15:26:09 -070054echo '*.2
Junio C Hamano1df092d2005-07-28 23:53:29 -070055two/*.4
56!*.7
57*.8' >one/.gitignore
58echo '!*.2
59!*.8' >one/two/.gitignore
Junio C Hamanof87f9492005-07-24 15:26:09 -070060
61test_expect_success \
Junio C Hamano5be60072007-07-02 22:52:14 -070062 'git ls-files --others with various exclude options.' \
63 'git ls-files --others \
Junio C Hamano1df092d2005-07-28 23:53:29 -070064 --exclude=\*.6 \
Junio C Hamanof87f9492005-07-24 15:26:09 -070065 --exclude-per-directory=.gitignore \
66 --exclude-from=.git/ignore \
67 >output &&
Johannes Schindelin5bd74502007-02-25 23:36:53 +010068 git diff expect output'
Pavel Roskinda7bc9b2005-08-10 22:15:02 -040069
Alex Riesend317e432005-11-02 14:05:45 +010070# Test \r\n (MSDOS-like systems)
Alex Riesen0dbc4e82006-02-12 19:05:34 +010071printf '*.1\r\n/*.3\r\n!*.6\r\n' >.gitignore
Alex Riesend317e432005-11-02 14:05:45 +010072
73test_expect_success \
Junio C Hamano5be60072007-07-02 22:52:14 -070074 'git ls-files --others with \r\n line endings.' \
75 'git ls-files --others \
Alex Riesend317e432005-11-02 14:05:45 +010076 --exclude=\*.6 \
77 --exclude-per-directory=.gitignore \
78 --exclude-from=.git/ignore \
79 >output &&
Johannes Schindelin5bd74502007-02-25 23:36:53 +010080 git diff expect output'
Alex Riesend317e432005-11-02 14:05:45 +010081
Johannes Schindelin0ba956d2007-05-22 01:12:17 +010082cat > excludes-file << EOF
83*.[1-8]
84e*
85EOF
86
Junio C Hamano5be60072007-07-02 22:52:14 -070087git config core.excludesFile excludes-file
Johannes Schindelin0ba956d2007-05-22 01:12:17 +010088
Johannes Schindelin637efc32007-11-15 06:27:57 +000089git status | grep "^# " > output
Johannes Schindelin0ba956d2007-05-22 01:12:17 +010090
91cat > expect << EOF
92# .gitignore
93# a.6
94# one/
95# output
96# three/
97EOF
98
99test_expect_success 'git-status honours core.excludesfile' \
Jeff King82ebb0b2008-03-12 17:36:36 -0400100 'test_cmp expect output'
Johannes Schindelin0ba956d2007-05-22 01:12:17 +0100101
Junio C Hamanod6b8fc32008-01-31 01:17:48 -0800102test_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
Pavel Roskinda7bc9b2005-08-10 22:15:02 -0400143test_done