Junio C Hamano | f87f949 | 2005-07-24 15:26:09 -0700 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
| 3 | # Copyright (c) 2005 Junio C Hamano |
| 4 | # |
| 5 | |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 6 | test_description='git ls-files --others --exclude |
Junio C Hamano | f87f949 | 2005-07-24 15:26:09 -0700 | [diff] [blame] | 7 | |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 8 | This test runs git ls-files --others and tests --exclude patterns. |
Junio C Hamano | f87f949 | 2005-07-24 15:26:09 -0700 | [diff] [blame] | 9 | ' |
| 10 | |
| 11 | . ./test-lib.sh |
| 12 | |
| 13 | rm -fr one three |
| 14 | for dir in . one one/two three |
| 15 | do |
| 16 | mkdir -p $dir && |
Junio C Hamano | 1df092d | 2005-07-28 23:53:29 -0700 | [diff] [blame] | 17 | for i in 1 2 3 4 5 6 7 8 |
Junio C Hamano | f87f949 | 2005-07-24 15:26:09 -0700 | [diff] [blame] | 18 | do |
| 19 | >$dir/a.$i |
| 20 | done |
| 21 | done |
Finn Arne Gangstad | dd482ee | 2009-02-10 15:20:17 +0100 | [diff] [blame] | 22 | >"#ignore1" |
| 23 | >"#ignore2" |
| 24 | >"#hidden" |
Junio C Hamano | f87f949 | 2005-07-24 15:26:09 -0700 | [diff] [blame] | 25 | |
| 26 | cat >expect <<EOF |
| 27 | a.2 |
| 28 | a.4 |
| 29 | a.5 |
Junio C Hamano | 1df092d | 2005-07-28 23:53:29 -0700 | [diff] [blame] | 30 | a.8 |
Junio C Hamano | f87f949 | 2005-07-24 15:26:09 -0700 | [diff] [blame] | 31 | one/a.3 |
| 32 | one/a.4 |
| 33 | one/a.5 |
Junio C Hamano | 1df092d | 2005-07-28 23:53:29 -0700 | [diff] [blame] | 34 | one/a.7 |
| 35 | one/two/a.2 |
Junio C Hamano | f87f949 | 2005-07-24 15:26:09 -0700 | [diff] [blame] | 36 | one/two/a.3 |
| 37 | one/two/a.5 |
Junio C Hamano | 1df092d | 2005-07-28 23:53:29 -0700 | [diff] [blame] | 38 | one/two/a.7 |
| 39 | one/two/a.8 |
Junio C Hamano | f87f949 | 2005-07-24 15:26:09 -0700 | [diff] [blame] | 40 | three/a.2 |
| 41 | three/a.3 |
| 42 | three/a.4 |
| 43 | three/a.5 |
Junio C Hamano | 1df092d | 2005-07-28 23:53:29 -0700 | [diff] [blame] | 44 | three/a.8 |
Junio C Hamano | f87f949 | 2005-07-24 15:26:09 -0700 | [diff] [blame] | 45 | EOF |
| 46 | |
| 47 | echo '.gitignore |
Finn Arne Gangstad | dd482ee | 2009-02-10 15:20:17 +0100 | [diff] [blame] | 48 | \#ignore1 |
| 49 | \#ignore2* |
| 50 | \#hid*n |
Junio C Hamano | f87f949 | 2005-07-24 15:26:09 -0700 | [diff] [blame] | 51 | output |
| 52 | expect |
| 53 | .gitignore |
Junio C Hamano | 1df092d | 2005-07-28 23:53:29 -0700 | [diff] [blame] | 54 | *.7 |
| 55 | !*.8' >.git/ignore |
Junio C Hamano | f87f949 | 2005-07-24 15:26:09 -0700 | [diff] [blame] | 56 | |
| 57 | echo '*.1 |
Junio C Hamano | 1df092d | 2005-07-28 23:53:29 -0700 | [diff] [blame] | 58 | /*.3 |
| 59 | !*.6' >.gitignore |
Junio C Hamano | f87f949 | 2005-07-24 15:26:09 -0700 | [diff] [blame] | 60 | echo '*.2 |
Junio C Hamano | 1df092d | 2005-07-28 23:53:29 -0700 | [diff] [blame] | 61 | two/*.4 |
| 62 | !*.7 |
| 63 | *.8' >one/.gitignore |
| 64 | echo '!*.2 |
| 65 | !*.8' >one/two/.gitignore |
Junio C Hamano | f87f949 | 2005-07-24 15:26:09 -0700 | [diff] [blame] | 66 | |
Nguyễn Thái Ngọc Duy | c28b3d6 | 2009-08-20 20:47:01 +0700 | [diff] [blame] | 67 | allignores='.gitignore one/.gitignore one/two/.gitignore' |
| 68 | |
Junio C Hamano | f87f949 | 2005-07-24 15:26:09 -0700 | [diff] [blame] | 69 | test_expect_success \ |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 70 | 'git ls-files --others with various exclude options.' \ |
| 71 | 'git ls-files --others \ |
Junio C Hamano | 1df092d | 2005-07-28 23:53:29 -0700 | [diff] [blame] | 72 | --exclude=\*.6 \ |
Junio C Hamano | f87f949 | 2005-07-24 15:26:09 -0700 | [diff] [blame] | 73 | --exclude-per-directory=.gitignore \ |
| 74 | --exclude-from=.git/ignore \ |
| 75 | >output && |
Junio C Hamano | 3af8286 | 2008-05-23 22:28:56 -0700 | [diff] [blame] | 76 | test_cmp expect output' |
Pavel Roskin | da7bc9b | 2005-08-10 22:15:02 -0400 | [diff] [blame] | 77 | |
Alex Riesen | d317e43 | 2005-11-02 14:05:45 +0100 | [diff] [blame] | 78 | # Test \r\n (MSDOS-like systems) |
Alex Riesen | 0dbc4e8 | 2006-02-12 19:05:34 +0100 | [diff] [blame] | 79 | printf '*.1\r\n/*.3\r\n!*.6\r\n' >.gitignore |
Alex Riesen | d317e43 | 2005-11-02 14:05:45 +0100 | [diff] [blame] | 80 | |
| 81 | test_expect_success \ |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 82 | 'git ls-files --others with \r\n line endings.' \ |
| 83 | 'git ls-files --others \ |
Alex Riesen | d317e43 | 2005-11-02 14:05:45 +0100 | [diff] [blame] | 84 | --exclude=\*.6 \ |
| 85 | --exclude-per-directory=.gitignore \ |
| 86 | --exclude-from=.git/ignore \ |
| 87 | >output && |
Junio C Hamano | 3af8286 | 2008-05-23 22:28:56 -0700 | [diff] [blame] | 88 | test_cmp expect output' |
Alex Riesen | d317e43 | 2005-11-02 14:05:45 +0100 | [diff] [blame] | 89 | |
Nguyễn Thái Ngọc Duy | c28b3d6 | 2009-08-20 20:47:01 +0700 | [diff] [blame] | 90 | test_expect_success 'setup skip-worktree gitignore' ' |
| 91 | git add $allignores && |
| 92 | git update-index --skip-worktree $allignores && |
| 93 | rm $allignores |
| 94 | ' |
| 95 | |
| 96 | test_expect_success \ |
| 97 | 'git ls-files --others with various exclude options.' \ |
| 98 | 'git ls-files --others \ |
| 99 | --exclude=\*.6 \ |
| 100 | --exclude-per-directory=.gitignore \ |
| 101 | --exclude-from=.git/ignore \ |
| 102 | >output && |
| 103 | test_cmp expect output' |
| 104 | |
| 105 | test_expect_success 'restore gitignore' ' |
| 106 | git checkout $allignores && |
| 107 | rm .git/index |
| 108 | ' |
| 109 | |
Finn Arne Gangstad | dd482ee | 2009-02-10 15:20:17 +0100 | [diff] [blame] | 110 | cat > excludes-file <<\EOF |
Johannes Schindelin | 0ba956d | 2007-05-22 01:12:17 +0100 | [diff] [blame] | 111 | *.[1-8] |
| 112 | e* |
Finn Arne Gangstad | dd482ee | 2009-02-10 15:20:17 +0100 | [diff] [blame] | 113 | \#* |
Johannes Schindelin | 0ba956d | 2007-05-22 01:12:17 +0100 | [diff] [blame] | 114 | EOF |
| 115 | |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 116 | git config core.excludesFile excludes-file |
Johannes Schindelin | 0ba956d | 2007-05-22 01:12:17 +0100 | [diff] [blame] | 117 | |
Johannes Schindelin | 637efc3 | 2007-11-15 06:27:57 +0000 | [diff] [blame] | 118 | git status | grep "^# " > output |
Johannes Schindelin | 0ba956d | 2007-05-22 01:12:17 +0100 | [diff] [blame] | 119 | |
| 120 | cat > expect << EOF |
| 121 | # .gitignore |
| 122 | # a.6 |
| 123 | # one/ |
| 124 | # output |
| 125 | # three/ |
| 126 | EOF |
| 127 | |
Nanako Shiraishi | 0cb0e14 | 2008-09-03 17:59:27 +0900 | [diff] [blame] | 128 | test_expect_success 'git status honors core.excludesfile' \ |
Jeff King | 82ebb0b | 2008-03-12 17:36:36 -0400 | [diff] [blame] | 129 | 'test_cmp expect output' |
Johannes Schindelin | 0ba956d | 2007-05-22 01:12:17 +0100 | [diff] [blame] | 130 | |
Junio C Hamano | d6b8fc3 | 2008-01-31 01:17:48 -0800 | [diff] [blame] | 131 | test_expect_success 'trailing slash in exclude allows directory match(1)' ' |
| 132 | |
| 133 | git ls-files --others --exclude=one/ >output && |
| 134 | if grep "^one/" output |
| 135 | then |
| 136 | echo Ooops |
| 137 | false |
| 138 | else |
| 139 | : happy |
| 140 | fi |
| 141 | |
| 142 | ' |
| 143 | |
| 144 | test_expect_success 'trailing slash in exclude allows directory match (2)' ' |
| 145 | |
| 146 | git ls-files --others --exclude=one/two/ >output && |
| 147 | if grep "^one/two/" output |
| 148 | then |
| 149 | echo Ooops |
| 150 | false |
| 151 | else |
| 152 | : happy |
| 153 | fi |
| 154 | |
| 155 | ' |
| 156 | |
| 157 | test_expect_success 'trailing slash in exclude forces directory match (1)' ' |
| 158 | |
Jonathan Nieder | a48fcd8 | 2010-10-30 20:46:54 -0500 | [diff] [blame] | 159 | >two && |
Junio C Hamano | d6b8fc3 | 2008-01-31 01:17:48 -0800 | [diff] [blame] | 160 | git ls-files --others --exclude=two/ >output && |
| 161 | grep "^two" output |
| 162 | |
| 163 | ' |
| 164 | |
| 165 | test_expect_success 'trailing slash in exclude forces directory match (2)' ' |
| 166 | |
| 167 | git ls-files --others --exclude=one/a.1/ >output && |
| 168 | grep "^one/a.1" output |
| 169 | |
| 170 | ' |
| 171 | |
Michael J Gruber | 32738ed | 2008-12-18 18:11:18 +0100 | [diff] [blame] | 172 | test_expect_success 'negated exclude matches can override previous ones' ' |
| 173 | |
| 174 | git ls-files --others --exclude="a.*" --exclude="!a.1" >output && |
| 175 | grep "^a.1" output |
| 176 | ' |
| 177 | |
Karsten Blees | c3c327d | 2013-05-29 22:32:36 +0200 | [diff] [blame^] | 178 | test_expect_success 'excluded directory overrides content patterns' ' |
| 179 | |
| 180 | git ls-files --others --exclude="one" --exclude="!one/a.1" >output && |
| 181 | if grep "^one/a.1" output |
| 182 | then |
| 183 | false |
| 184 | fi |
| 185 | ' |
| 186 | |
| 187 | test_expect_success 'negated directory doesn'\''t affect content patterns' ' |
| 188 | |
| 189 | git ls-files --others --exclude="!one" --exclude="one/a.1" >output && |
| 190 | if grep "^one/a.1" output |
| 191 | then |
| 192 | false |
| 193 | fi |
| 194 | ' |
| 195 | |
Junio C Hamano | 472e746 | 2010-01-08 23:07:17 -0800 | [diff] [blame] | 196 | test_expect_success 'subdirectory ignore (setup)' ' |
| 197 | mkdir -p top/l1/l2 && |
| 198 | ( |
| 199 | cd top && |
| 200 | git init && |
| 201 | echo /.gitignore >.gitignore && |
| 202 | echo l1 >>.gitignore && |
| 203 | echo l2 >l1/.gitignore && |
| 204 | >l1/l2/l1 |
| 205 | ) |
| 206 | ' |
| 207 | |
| 208 | test_expect_success 'subdirectory ignore (toplevel)' ' |
| 209 | ( |
| 210 | cd top && |
| 211 | git ls-files -o --exclude-standard |
| 212 | ) >actual && |
| 213 | >expect && |
| 214 | test_cmp expect actual |
| 215 | ' |
| 216 | |
| 217 | test_expect_success 'subdirectory ignore (l1/l2)' ' |
| 218 | ( |
| 219 | cd top/l1/l2 && |
| 220 | git ls-files -o --exclude-standard |
| 221 | ) >actual && |
| 222 | >expect && |
| 223 | test_cmp expect actual |
| 224 | ' |
| 225 | |
Junio C Hamano | 48ffef9 | 2010-01-08 23:05:41 -0800 | [diff] [blame] | 226 | test_expect_success 'subdirectory ignore (l1)' ' |
Junio C Hamano | 472e746 | 2010-01-08 23:07:17 -0800 | [diff] [blame] | 227 | ( |
| 228 | cd top/l1 && |
| 229 | git ls-files -o --exclude-standard |
| 230 | ) >actual && |
| 231 | >expect && |
| 232 | test_cmp expect actual |
| 233 | ' |
| 234 | |
Karsten Blees | 184d2a8 | 2013-04-15 21:08:02 +0200 | [diff] [blame] | 235 | test_expect_success 'show/hide empty ignored directory (setup)' ' |
| 236 | rm top/l1/l2/l1 && |
| 237 | rm top/l1/.gitignore |
| 238 | ' |
| 239 | |
| 240 | test_expect_success 'show empty ignored directory with --directory' ' |
| 241 | ( |
| 242 | cd top && |
| 243 | git ls-files -o -i --exclude l1 --directory |
| 244 | ) >actual && |
| 245 | echo l1/ >expect && |
| 246 | test_cmp expect actual |
| 247 | ' |
| 248 | |
| 249 | test_expect_success 'hide empty ignored directory with --no-empty-directory' ' |
| 250 | ( |
| 251 | cd top && |
| 252 | git ls-files -o -i --exclude l1 --directory --no-empty-directory |
| 253 | ) >actual && |
| 254 | >expect && |
| 255 | test_cmp expect actual |
| 256 | ' |
| 257 | |
Karsten Blees | 5bd8e2d | 2013-04-15 21:10:05 +0200 | [diff] [blame] | 258 | test_expect_success 'show/hide empty ignored sub-directory (setup)' ' |
| 259 | > top/l1/tracked && |
| 260 | ( |
| 261 | cd top && |
| 262 | git add -f l1/tracked |
| 263 | ) |
| 264 | ' |
| 265 | |
| 266 | test_expect_success 'show empty ignored sub-directory with --directory' ' |
| 267 | ( |
| 268 | cd top && |
| 269 | git ls-files -o -i --exclude l1 --directory |
| 270 | ) >actual && |
| 271 | echo l1/l2/ >expect && |
| 272 | test_cmp expect actual |
| 273 | ' |
| 274 | |
| 275 | test_expect_success 'hide empty ignored sub-directory with --no-empty-directory' ' |
| 276 | ( |
| 277 | cd top && |
| 278 | git ls-files -o -i --exclude l1 --directory --no-empty-directory |
| 279 | ) >actual && |
| 280 | >expect && |
| 281 | test_cmp expect actual |
| 282 | ' |
| 283 | |
Nguyễn Thái Ngọc Duy | a3ea4d7 | 2012-10-15 13:24:36 +0700 | [diff] [blame] | 284 | test_expect_success 'pattern matches prefix completely' ' |
| 285 | : >expect && |
| 286 | git ls-files -i -o --exclude "/three/a.3[abc]" >actual && |
| 287 | test_cmp expect actual |
| 288 | ' |
| 289 | |
Nguyễn Thái Ngọc Duy | 237ec6e | 2012-10-15 13:26:02 +0700 | [diff] [blame] | 290 | test_expect_success 'ls-files with "**" patterns' ' |
| 291 | cat <<\EOF >expect && |
| 292 | a.1 |
| 293 | one/a.1 |
| 294 | one/two/a.1 |
| 295 | three/a.1 |
| 296 | EOF |
| 297 | git ls-files -o -i --exclude "**/a.1" >actual |
| 298 | test_cmp expect actual |
| 299 | ' |
| 300 | |
| 301 | |
| 302 | test_expect_success 'ls-files with "**" patterns and no slashes' ' |
| 303 | : >expect && |
| 304 | git ls-files -o -i --exclude "one**a.1" >actual && |
| 305 | test_cmp expect actual |
| 306 | ' |
| 307 | |
Pavel Roskin | da7bc9b | 2005-08-10 22:15:02 -0400 | [diff] [blame] | 308 | test_done |