| 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='git-status ignored files' |
| 4 | |
| 5 | . ./test-lib.sh |
| 6 | |
| 7 | cat >expected <<\EOF |
| 8 | ?? .gitignore |
| 9 | ?? actual |
| 10 | ?? expected |
| 11 | ?? untracked/ |
| 12 | !! untracked/ignored |
| 13 | EOF |
| 14 | |
| 15 | test_expect_success 'status untracked directory with --ignored' ' |
| 16 | echo "ignored" >.gitignore && |
| 17 | mkdir untracked && |
| 18 | : >untracked/ignored && |
| 19 | : >untracked/uncommitted && |
| 20 | git status --porcelain --ignored >actual && |
| 21 | test_filter_gitconfig actual && |
| 22 | test_cmp expected actual |
| 23 | ' |
| 24 | |
| 25 | test_expect_success 'same with gitignore starting with BOM' ' |
| 26 | printf "\357\273\277ignored\n" >.gitignore && |
| 27 | mkdir -p untracked && |
| 28 | : >untracked/ignored && |
| 29 | : >untracked/uncommitted && |
| 30 | git status --porcelain --ignored >actual && |
| 31 | test_filter_gitconfig actual && |
| 32 | test_cmp expected actual |
| 33 | ' |
| 34 | |
| 35 | test_expect_success 'status untracked files --ignored with pathspec (no match)' ' |
| 36 | git status --porcelain --ignored -- untracked/i >actual && |
| 37 | test_must_be_empty actual && |
| 38 | git status --porcelain --ignored -- untracked/u >actual && |
| 39 | test_must_be_empty actual |
| 40 | ' |
| 41 | |
| 42 | test_expect_success 'status untracked files --ignored with pathspec (literal match)' ' |
| 43 | git status --porcelain --ignored -- untracked/ignored >actual && |
| 44 | echo "!! untracked/ignored" >expected && |
| 45 | test_filter_gitconfig actual && |
| 46 | test_cmp expected actual && |
| 47 | git status --porcelain --ignored -- untracked/uncommitted >actual && |
| 48 | echo "?? untracked/uncommitted" >expected && |
| 49 | test_filter_gitconfig actual && |
| 50 | test_cmp expected actual |
| 51 | ' |
| 52 | |
| 53 | test_expect_success 'status untracked files --ignored with pathspec (glob match)' ' |
| 54 | git status --porcelain --ignored -- untracked/i\* >actual && |
| 55 | echo "!! untracked/ignored" >expected && |
| 56 | test_filter_gitconfig actual && |
| 57 | test_cmp expected actual && |
| 58 | git status --porcelain --ignored -- untracked/u\* >actual && |
| 59 | echo "?? untracked/uncommitted" >expected && |
| 60 | test_filter_gitconfig actual && |
| 61 | test_cmp expected actual |
| 62 | ' |
| 63 | |
| 64 | cat >expected <<\EOF |
| 65 | ?? .gitignore |
| 66 | ?? actual |
| 67 | ?? expected |
| 68 | ?? untracked/uncommitted |
| 69 | !! untracked/ignored |
| 70 | EOF |
| 71 | |
| 72 | test_expect_success 'status untracked directory with --ignored -u' ' |
| 73 | git status --porcelain --ignored -u >actual && |
| 74 | test_filter_gitconfig actual && |
| 75 | test_cmp expected actual |
| 76 | ' |
| 77 | cat >expected <<\EOF |
| 78 | ?? untracked/ |
| 79 | !! untracked/ignored |
| 80 | EOF |
| 81 | |
| 82 | test_expect_success 'status of untracked directory with --ignored works with or without prefix' ' |
| 83 | git status --porcelain --ignored >tmp && |
| 84 | grep untracked/ tmp >actual && |
| 85 | rm tmp && |
| 86 | test_filter_gitconfig actual && |
| 87 | test_cmp expected actual && |
| 88 | |
| 89 | git status --porcelain --ignored untracked/ >actual && |
| 90 | test_filter_gitconfig actual && |
| 91 | test_cmp expected actual |
| 92 | ' |
| 93 | |
| 94 | cat >expected <<\EOF |
| 95 | ?? untracked/uncommitted |
| 96 | !! untracked/ignored |
| 97 | EOF |
| 98 | |
| 99 | test_expect_success 'status prefixed untracked sub-directory with --ignored -u' ' |
| 100 | git status --porcelain --ignored -u untracked/ >actual && |
| 101 | test_filter_gitconfig actual && |
| 102 | test_cmp expected actual |
| 103 | ' |
| 104 | |
| 105 | cat >expected <<\EOF |
| 106 | ?? .gitignore |
| 107 | ?? actual |
| 108 | ?? expected |
| 109 | !! ignored/ |
| 110 | EOF |
| 111 | |
| 112 | test_expect_success 'status ignored directory with --ignore' ' |
| 113 | rm -rf untracked && |
| 114 | mkdir ignored && |
| 115 | : >ignored/uncommitted && |
| 116 | git status --porcelain --ignored >actual && |
| 117 | test_filter_gitconfig actual && |
| 118 | test_cmp expected actual |
| 119 | ' |
| 120 | |
| 121 | cat >expected <<\EOF |
| 122 | ?? .gitignore |
| 123 | ?? actual |
| 124 | ?? expected |
| 125 | !! ignored/uncommitted |
| 126 | EOF |
| 127 | |
| 128 | test_expect_success 'status ignored directory with --ignore -u' ' |
| 129 | git status --porcelain --ignored -u >actual && |
| 130 | test_filter_gitconfig actual && |
| 131 | test_cmp expected actual |
| 132 | ' |
| 133 | |
| 134 | cat >expected <<\EOF |
| 135 | ?? .gitignore |
| 136 | ?? actual |
| 137 | ?? expected |
| 138 | EOF |
| 139 | |
| 140 | test_expect_success 'status empty untracked directory with --ignore' ' |
| 141 | rm -rf ignored && |
| 142 | mkdir untracked-ignored && |
| 143 | mkdir untracked-ignored/test && |
| 144 | git status --porcelain --ignored >actual && |
| 145 | test_filter_gitconfig actual && |
| 146 | test_cmp expected actual |
| 147 | ' |
| 148 | |
| 149 | cat >expected <<\EOF |
| 150 | ?? .gitignore |
| 151 | ?? actual |
| 152 | ?? expected |
| 153 | EOF |
| 154 | |
| 155 | test_expect_success 'status empty untracked directory with --ignore -u' ' |
| 156 | git status --porcelain --ignored -u >actual && |
| 157 | test_filter_gitconfig actual && |
| 158 | test_cmp expected actual |
| 159 | ' |
| 160 | |
| 161 | cat >expected <<\EOF |
| 162 | ?? .gitignore |
| 163 | ?? actual |
| 164 | ?? expected |
| 165 | !! untracked-ignored/ |
| 166 | EOF |
| 167 | |
| 168 | test_expect_success 'status untracked directory with ignored files with --ignore' ' |
| 169 | : >untracked-ignored/ignored && |
| 170 | : >untracked-ignored/test/ignored && |
| 171 | git status --porcelain --ignored >actual && |
| 172 | test_filter_gitconfig actual && |
| 173 | test_cmp expected actual |
| 174 | ' |
| 175 | |
| 176 | cat >expected <<\EOF |
| 177 | ?? .gitignore |
| 178 | ?? actual |
| 179 | ?? expected |
| 180 | !! untracked-ignored/ignored |
| 181 | !! untracked-ignored/test/ignored |
| 182 | EOF |
| 183 | |
| 184 | test_expect_success 'status untracked directory with ignored files with --ignore -u' ' |
| 185 | git status --porcelain --ignored -u >actual && |
| 186 | test_filter_gitconfig actual && |
| 187 | test_cmp expected actual |
| 188 | ' |
| 189 | |
| 190 | cat >expected <<\EOF |
| 191 | ?? .gitignore |
| 192 | ?? actual |
| 193 | ?? expected |
| 194 | EOF |
| 195 | |
| 196 | test_expect_success 'status ignored tracked directory with --ignore' ' |
| 197 | rm -rf untracked-ignored && |
| 198 | mkdir tracked && |
| 199 | : >tracked/committed && |
| 200 | git add tracked/committed && |
| 201 | git commit -m. && |
| 202 | echo "tracked" >.gitignore && |
| 203 | git status --porcelain --ignored >actual && |
| 204 | test_filter_gitconfig actual && |
| 205 | test_cmp expected actual |
| 206 | ' |
| 207 | |
| 208 | cat >expected <<\EOF |
| 209 | ?? .gitignore |
| 210 | ?? actual |
| 211 | ?? expected |
| 212 | EOF |
| 213 | |
| 214 | test_expect_success 'status ignored tracked directory with --ignore -u' ' |
| 215 | git status --porcelain --ignored -u >actual && |
| 216 | test_filter_gitconfig actual && |
| 217 | test_cmp expected actual |
| 218 | ' |
| 219 | |
| 220 | cat >expected <<\EOF |
| 221 | ?? .gitignore |
| 222 | ?? actual |
| 223 | ?? expected |
| 224 | EOF |
| 225 | |
| 226 | test_expect_success 'status ignored tracked directory and ignored file with --ignore' ' |
| 227 | echo "committed" >>.gitignore && |
| 228 | git status --porcelain --ignored >actual && |
| 229 | test_filter_gitconfig actual && |
| 230 | test_cmp expected actual |
| 231 | ' |
| 232 | |
| 233 | cat >expected <<\EOF |
| 234 | ?? .gitignore |
| 235 | ?? actual |
| 236 | ?? expected |
| 237 | EOF |
| 238 | |
| 239 | test_expect_success 'status ignored tracked directory and ignored file with --ignore -u' ' |
| 240 | git status --porcelain --ignored -u >actual && |
| 241 | test_filter_gitconfig actual && |
| 242 | test_cmp expected actual |
| 243 | ' |
| 244 | |
| 245 | cat >expected <<\EOF |
| 246 | ?? .gitignore |
| 247 | ?? actual |
| 248 | ?? expected |
| 249 | !! tracked/uncommitted |
| 250 | EOF |
| 251 | |
| 252 | test_expect_success 'status ignored tracked directory and uncommitted file with --ignore' ' |
| 253 | echo "tracked" >.gitignore && |
| 254 | : >tracked/uncommitted && |
| 255 | git status --porcelain --ignored >actual && |
| 256 | test_filter_gitconfig actual && |
| 257 | test_cmp expected actual |
| 258 | ' |
| 259 | |
| 260 | cat >expected <<\EOF |
| 261 | ?? .gitignore |
| 262 | ?? actual |
| 263 | ?? expected |
| 264 | !! tracked/uncommitted |
| 265 | EOF |
| 266 | |
| 267 | test_expect_success 'status ignored tracked directory and uncommitted file with --ignore -u' ' |
| 268 | git status --porcelain --ignored -u >actual && |
| 269 | test_filter_gitconfig actual && |
| 270 | test_cmp expected actual |
| 271 | ' |
| 272 | |
| 273 | cat >expected <<\EOF |
| 274 | ?? .gitignore |
| 275 | ?? actual |
| 276 | ?? expected |
| 277 | !! tracked/ignored/ |
| 278 | EOF |
| 279 | |
| 280 | test_expect_success 'status ignored tracked directory with uncommitted file in untracked subdir with --ignore' ' |
| 281 | rm -rf tracked/uncommitted && |
| 282 | mkdir tracked/ignored && |
| 283 | : >tracked/ignored/uncommitted && |
| 284 | git status --porcelain --ignored >actual && |
| 285 | test_filter_gitconfig actual && |
| 286 | test_cmp expected actual |
| 287 | ' |
| 288 | |
| 289 | cat >expected <<\EOF |
| 290 | ?? .gitignore |
| 291 | ?? actual |
| 292 | ?? expected |
| 293 | !! tracked/ignored/uncommitted |
| 294 | EOF |
| 295 | |
| 296 | test_expect_success 'status ignored tracked directory with uncommitted file in untracked subdir with --ignore -u' ' |
| 297 | git status --porcelain --ignored -u >actual && |
| 298 | test_filter_gitconfig actual && |
| 299 | test_cmp expected actual |
| 300 | ' |
| 301 | |
| 302 | cat >expected <<\EOF |
| 303 | ?? .gitignore |
| 304 | ?? actual |
| 305 | ?? expected |
| 306 | !! tracked/ignored/uncommitted |
| 307 | EOF |
| 308 | |
| 309 | test_expect_success 'status ignored tracked directory with uncommitted file in tracked subdir with --ignore' ' |
| 310 | : >tracked/ignored/committed && |
| 311 | git add -f tracked/ignored/committed && |
| 312 | git commit -m. && |
| 313 | git status --porcelain --ignored >actual && |
| 314 | test_filter_gitconfig actual && |
| 315 | test_cmp expected actual |
| 316 | ' |
| 317 | |
| 318 | cat >expected <<\EOF |
| 319 | ?? .gitignore |
| 320 | ?? actual |
| 321 | ?? expected |
| 322 | !! tracked/ignored/uncommitted |
| 323 | EOF |
| 324 | |
| 325 | test_expect_success 'status ignored tracked directory with uncommitted file in tracked subdir with --ignore -u' ' |
| 326 | git status --porcelain --ignored -u >actual && |
| 327 | test_filter_gitconfig actual && |
| 328 | test_cmp expected actual |
| 329 | ' |
| 330 | |
| 331 | cat >expected <<\EOF |
| 332 | !! tracked/submodule/ |
| 333 | EOF |
| 334 | |
| 335 | test_expect_success 'status ignores submodule in excluded directory' ' |
| 336 | git init tracked/submodule && |
| 337 | test_commit -C tracked/submodule initial && |
| 338 | git status --porcelain --ignored -u tracked/submodule >actual && |
| 339 | test_filter_gitconfig actual && |
| 340 | test_cmp expected actual |
| 341 | ' |
| 342 | |
| 343 | test_done |