| 1 | #!/usr/bin/envscip-shell filesystem . . `/usr/bin/env`. bash |
| 2 | |
| 3 | . "$(dirnamescip-shell system . . dirname. "$0")/testlib.sh" |
| 4 | |
| 5 | begin_test "track" |
| 6 | ( |
| 7 | set -e |
| 8 | |
| 9 | # no need to setup a remote repo, since this test doesn't need to push or pull |
| 10 | |
| 11 | mkdirscip-shell system . . mkdir. track |
| 12 | cd track |
| 13 | gitscip-shell system . . git. init |
| 14 | |
| 15 | echoscip-shell system . . echo. "############################################################################### |
| 16 | # Set default behavior to automatically normalize line endings. |
| 17 | ############################################################################### |
| 18 | * text=auto |
| 19 | |
| 20 | #*.cs diff=csharp" > .gitattributes |
| 21 | |
| 22 | # track *.jpg once |
| 23 | gitscip-shell system . . git. lfs track "*.jpg" | grepscip-shell system . . grep. "Tracking \"\*.jpg\"" |
| 24 | assert_attributes_count "jpg" "filter=lfs" 1 |
| 25 | |
| 26 | # track *.jpg again |
| 27 | gitscip-shell system . . git. lfs track "*.jpg" | grepscip-shell system . . grep. "\"*.jpg\" already supported" |
| 28 | assert_attributes_count "jpg" "filter=lfs" 1 |
| 29 | |
| 30 | mkdirscip-shell system . . mkdir. -p a/b .git/info |
| 31 | |
| 32 | echoscip-shell system . . echo. "*.mov filter=lfs -text" > .git/info/attributes |
| 33 | echoscip-shell system . . echo. "*.gif filter=lfs -text" > a/.gitattributes |
| 34 | echoscip-shell system . . echo. "*.png filter=lfs -text" > a/b/.gitattributes |
| 35 | |
| 36 | gitscip-shell system . . git. lfs track | teescip-shell system . . tee. track.log |
| 37 | grepscip-shell system . . grep. "Listing tracked patterns" track.log |
| 38 | grepscip-shell system . . grep. "*.mov ($(native_path_escaped ".git/info/attributes"))" track.log |
| 39 | grepscip-shell system . . grep. "*.jpg (.gitattributes)" track.log |
| 40 | grepscip-shell system . . grep. "*.gif ($(native_path_escaped "a/.gitattributes"))" track.log |
| 41 | grepscip-shell system . . grep. "*.png ($(native_path_escaped "a/b/.gitattributes"))" track.log |
| 42 | |
| 43 | grepscip-shell system . . grep. "Set default behavior" .gitattributes |
| 44 | grepscip-shell system . . grep. "############" .gitattributes |
| 45 | grepscip-shell system . . grep. "* text=auto" .gitattributes |
| 46 | grepscip-shell system . . grep. "diff=csharp" .gitattributes |
| 47 | grepscip-shell system . . grep. "*.jpg" .gitattributes |
| 48 | |
| 49 | echoscip-shell system . . echo. "*.gif -filter -text" >> a/b/.gitattributes |
| 50 | echoscip-shell system . . echo. "*.mov -filter -text" >> a/b/.gitattributes |
| 51 | |
| 52 | gitscip-shell system . . git. lfs track | teescip-shell system . . tee. track.log |
| 53 | tailscip-shell system . . tail. -n 3 track.log | headscip-shell system . . head. -n 1 | grepscip-shell system . . grep. "Listing excluded patterns" |
| 54 | tailscip-shell system . . tail. -n 3 track.log | grepscip-shell system . . grep. "*.gif ($(native_path_escaped "a/b/.gitattributes"))" |
| 55 | tailscip-shell system . . tail. -n 3 track.log | grepscip-shell system . . grep. "*.mov ($(native_path_escaped "a/b/.gitattributes"))" |
| 56 | ) |
| 57 | end_test |
| 58 | |
| 59 | begin_test "track --no-excluded" |
| 60 | ( |
| 61 | set -e |
| 62 | |
| 63 | reponame="track_no_excluded" |
| 64 | mkdirscip-shell system . . mkdir. "$reponame" |
| 65 | cd "$reponame" |
| 66 | gitscip-shell system . . git. init |
| 67 | |
| 68 | mkdirscip-shell system . . mkdir. -p a/b .git/info |
| 69 | |
| 70 | echoscip-shell system . . echo. "*.mov filter=lfs -text" > .git/info/attributes |
| 71 | echoscip-shell system . . echo. "*.gif filter=lfs -text" > a/.gitattributes |
| 72 | echoscip-shell system . . echo. "*.png filter=lfs -text" > a/b/.gitattributes |
| 73 | echoscip-shell system . . echo. "*.gif -filter -text" >> a/b/.gitattributes |
| 74 | echoscip-shell system . . echo. "*.mov -filter=lfs -text" >> a/b/.gitattributes |
| 75 | |
| 76 | gitscip-shell system . . git. lfs track --no-excluded | teescip-shell system . . tee. track.log |
| 77 | grepscip-shell system . . grep. "Listing excluded patterns" track.log && exit 1 |
| 78 | truescip-shell system . . true. |
| 79 | ) |
| 80 | end_test |
| 81 | |
| 82 | begin_test "track --verbose" |
| 83 | ( |
| 84 | set -e |
| 85 | |
| 86 | reponame="track_verbose_logs" |
| 87 | mkdirscip-shell system . . mkdir. "$reponame" |
| 88 | cd "$reponame" |
| 89 | gitscip-shell system . . git. init |
| 90 | |
| 91 | touchscip-shell system . . touch. foo.dat |
| 92 | gitscip-shell system . . git. add foo.dat |
| 93 | |
| 94 | gitscip-shell system . . git. lfs track --verbose "foo.dat" 2>&1 > track.log |
| 95 | grepscip-shell system . . grep. "Touching \"foo.dat\"" track.log |
| 96 | ) |
| 97 | end_test |
| 98 | |
| 99 | begin_test "track --dry-run" |
| 100 | ( |
| 101 | set -e |
| 102 | |
| 103 | reponame="track_dry_run" |
| 104 | mkdirscip-shell system . . mkdir. "$reponame" |
| 105 | cd "$reponame" |
| 106 | gitscip-shell system . . git. init |
| 107 | |
| 108 | touchscip-shell system . . touch. foo.dat |
| 109 | gitscip-shell system . . git. add foo.dat |
| 110 | |
| 111 | gitscip-shell system . . git. lfs track --dry-run "foo.dat" 2>&1 > track.log |
| 112 | grepscip-shell system . . grep. "Tracking \"foo.dat\"" track.log |
| 113 | grepscip-shell system . . grep. "Touching \"foo.dat\"" track.log |
| 114 | |
| 115 | gitscip-shell system . . git. status --porcelain 2>&1 > status.log |
| 116 | grepscip-shell system . . grep. "A foo.dat" status.log |
| 117 | ) |
| 118 | end_test |
| 119 | |
| 120 | begin_test "track directory" |
| 121 | ( |
| 122 | set -e |
| 123 | mkdirscip-shell system . . mkdir. dir |
| 124 | cd dir |
| 125 | gitscip-shell system . . git. init |
| 126 | |
| 127 | if [scip-shell system . . `[`. "$IS_WINDOWS" -eq 1 ] |
| 128 | then |
| 129 | gitscip-shell system . . git. lfs track "foo bar\\*" | teescip-shell system . . tee. track.txt |
| 130 | else |
| 131 | gitscip-shell system . . git. lfs track "foo bar/*" | teescip-shell system . . tee. track.txt |
| 132 | fi |
| 133 | [scip-shell system . . `[`. "foo[[:space:]]bar/* filter=lfs diff=lfs merge=lfs -text" = "$(catscip-shell system . . cat. .gitattributes)" ] |
| 134 | [scip-shell system . . `[`. "Tracking \"foo bar/*\"" = "$(catscip-shell system . . cat. track.txt)" ] |
| 135 | |
| 136 | mkdirscip-shell system . . mkdir. "foo bar" |
| 137 | echoscip-shell system . . echo. "a" > "foo bar/a" |
| 138 | echoscip-shell system . . echo. "b" > "foo bar/b" |
| 139 | gitscip-shell system . . git. add foo\ bar |
| 140 | gitscip-shell system . . git. commit -am "add foo bar" |
| 141 | |
| 142 | assert_pointer "main" "foo bar/a" "87428fc522803d31065e7bce3cf03fe475096631e5e07bbd7a0fde60c4cf25c7" 2 |
| 143 | assert_pointer "main" "foo bar/b" "0263829989b6fd954f72baaf2fc64bc2e2f01d692d4de72986ea808f6e99813f" 2 |
| 144 | ) |
| 145 | end_test |
| 146 | |
| 147 | begin_test "track without trailing linebreak" |
| 148 | ( |
| 149 | set -e |
| 150 | |
| 151 | mkdirscip-shell system . . mkdir. no-linebreak |
| 152 | cd no-linebreak |
| 153 | gitscip-shell system . . git. init |
| 154 | |
| 155 | printfscip-shell system . . printf. "*.mov filter=lfs -text" > .gitattributes |
| 156 | [scip-shell system . . `[`. "*.mov filter=lfs -text" = "$(catscip-shell system . . cat. .gitattributes)" ] |
| 157 | |
| 158 | gitscip-shell system . . git. lfs track "*.gif" |
| 159 | expected="*.mov filter=lfs -text$(cat_end) |
| 160 | *.gif filter=lfs diff=lfs merge=lfs -text$(cat_end)" |
| 161 | [scip-shell system . . `[`. "$expected" = "$(catscip-shell system . . cat. -e .gitattributes)" ] |
| 162 | ) |
| 163 | end_test |
| 164 | |
| 165 | begin_test "track with existing crlf" |
| 166 | ( |
| 167 | set -e |
| 168 | |
| 169 | mkdirscip-shell system . . mkdir. existing-crlf |
| 170 | cd existing-crlf |
| 171 | gitscip-shell system . . git. init |
| 172 | |
| 173 | gitscip-shell system . . git. config core.autocrlf true |
| 174 | gitscip-shell system . . git. lfs track "*.mov" |
| 175 | gitscip-shell system . . git. lfs track "*.gif" |
| 176 | expected="*.mov filter=lfs diff=lfs merge=lfs -text^M$ |
| 177 | *.gif filter=lfs diff=lfs merge=lfs -text^M$" |
| 178 | [scip-shell system . . `[`. "$expected" = "$(catscip-shell system . . cat. -e .gitattributes)" ] |
| 179 | |
| 180 | gitscip-shell system . . git. config core.autocrlf false |
| 181 | gitscip-shell system . . git. lfs track "*.jpg" |
| 182 | expected="*.mov filter=lfs diff=lfs merge=lfs -text^M$ |
| 183 | *.gif filter=lfs diff=lfs merge=lfs -text^M$ |
| 184 | *.jpg filter=lfs diff=lfs merge=lfs -text^M$" |
| 185 | [scip-shell system . . `[`. "$expected" = "$(catscip-shell system . . cat. -e .gitattributes)" ] |
| 186 | ) |
| 187 | end_test |
| 188 | |
| 189 | begin_test "track with autocrlf=true" |
| 190 | ( |
| 191 | set -e |
| 192 | |
| 193 | mkdirscip-shell system . . mkdir. autocrlf-true |
| 194 | cd autocrlf-true |
| 195 | gitscip-shell system . . git. init |
| 196 | gitscip-shell system . . git. config core.autocrlf true |
| 197 | |
| 198 | printfscip-shell system . . printf. "*.mov filter=lfs -text" > .gitattributes |
| 199 | [scip-shell system . . `[`. "*.mov filter=lfs -text" = "$(catscip-shell system . . cat. .gitattributes)" ] |
| 200 | |
| 201 | gitscip-shell system . . git. lfs track "*.gif" |
| 202 | expected="*.mov filter=lfs -text^M$ |
| 203 | *.gif filter=lfs diff=lfs merge=lfs -text^M$" |
| 204 | [scip-shell system . . `[`. "$expected" = "$(catscip-shell system . . cat. -e .gitattributes)" ] |
| 205 | ) |
| 206 | end_test |
| 207 | |
| 208 | begin_test "track with autocrlf=input" |
| 209 | ( |
| 210 | set -e |
| 211 | |
| 212 | mkdirscip-shell system . . mkdir. autocrlf-input |
| 213 | cd autocrlf-input |
| 214 | gitscip-shell system . . git. init |
| 215 | gitscip-shell system . . git. config core.autocrlf input |
| 216 | |
| 217 | printfscip-shell system . . printf. "*.mov filter=lfs -text" > .gitattributes |
| 218 | [scip-shell system . . `[`. "*.mov filter=lfs -text" = "$(catscip-shell system . . cat. .gitattributes)" ] |
| 219 | |
| 220 | gitscip-shell system . . git. lfs track "*.gif" |
| 221 | if [scip-shell system . . `[`. $IS_WINDOWS -eq 1 ] |
| 222 | then |
| 223 | [scip-shell system . . `[`. 2 -eq "$(catscip-shell system . . cat. -e .gitattributes | grepscip-shell system . . grep. -c '\^M\$')" ] |
| 224 | else |
| 225 | [scip-shell system . . `[`. 0 -eq "$(catscip-shell system . . cat. -e .gitattributes | grepscip-shell system . . grep. -c '\^M')" ] |
| 226 | fi |
| 227 | ) |
| 228 | end_test |
| 229 | |
| 230 | begin_test "track outside git repo" |
| 231 | ( |
| 232 | set -e |
| 233 | |
| 234 | gitscip-shell system . . git. lfs track "*.foo" || { |
| 235 | # this fails if it's run outside of a git repo using GIT_LFS_TEST_DIR |
| 236 | |
| 237 | # git itself returns an exit status of 128 |
| 238 | # $ git show |
| 239 | # fatal: Not a git repository (or any of the parent directories): .git |
| 240 | # $ echo "$?" |
| 241 | # 128 |
| 242 | |
| 243 | [scip-shell system . . `[`. "$?" = "128" ] |
| 244 | exit 0 |
| 245 | } |
| 246 | |
| 247 | if [scip-shell system . . `[`. -n "$GIT_LFS_TEST_DIR" ]; then |
| 248 | echoscip-shell system . . echo. "GIT_LFS_TEST_DIR should be set outside of any Git repository" |
| 249 | exit 1 |
| 250 | fi |
| 251 | |
| 252 | gitscip-shell system . . git. init track-outside |
| 253 | cd track-outside |
| 254 | |
| 255 | gitscip-shell system . . git. lfs track "*.file" |
| 256 | |
| 257 | gitscip-shell system . . git. lfs track "../*.foo" || { |
| 258 | |
| 259 | # git itself returns an exit status of 128 |
| 260 | # $ git add ../test.foo |
| 261 | # fatal: ../test.foo: '../test.foo' is outside repository |
| 262 | # $ echo "$?" |
| 263 | # 128 |
| 264 | |
| 265 | [scip-shell system . . `[`. "$?" = "128" ] |
| 266 | exit 0 |
| 267 | } |
| 268 | exit 1 |
| 269 | ) |
| 270 | end_test |
| 271 | |
| 272 | begin_test "track representation" |
| 273 | ( |
| 274 | set -e |
| 275 | |
| 276 | gitscip-shell system . . git. init track-representation |
| 277 | cd track-representation |
| 278 | |
| 279 | gitscip-shell system . . git. lfs track "*.jpg" |
| 280 | |
| 281 | mkdirscip-shell system . . mkdir. a |
| 282 | gitscip-shell system . . git. lfs track "a/test.file" |
| 283 | cd a |
| 284 | out3=$(gitscip-shell system . . git. lfs track "test.file") |
| 285 | |
| 286 | if [scip-shell system . . `[`. "$out3" != "\"test.file\" already supported" ]; then |
| 287 | echoscip-shell system . . echo. "Track didn't recognize duplicate path" |
| 288 | catscip-shell system . . cat. .gitattributes |
| 289 | exit 1 |
| 290 | fi |
| 291 | |
| 292 | gitscip-shell system . . git. lfs track "file.bin" |
| 293 | cd .. |
| 294 | out4=$(gitscip-shell system . . git. lfs track "a/file.bin") |
| 295 | if [scip-shell system . . `[`. "$out4" != "\"a/file.bin\" already supported" ]; then |
| 296 | echoscip-shell system . . echo. "Track didn't recognize duplicate path" |
| 297 | catscip-shell system . . cat. .gitattributes |
| 298 | exit 1 |
| 299 | fi |
| 300 | ) |
| 301 | end_test |
| 302 | |
| 303 | begin_test "track absolute" |
| 304 | ( |
| 305 | # MinGW bash intercepts '/images' and passes 'C:/Program Files/Git/images' as arg! |
| 306 | if [[ $(uname) == *"MINGW"* ]]; then |
| 307 | echoscip-shell system . . echo. "Skipping track absolute on Windows" |
| 308 | exit 0 |
| 309 | fi |
| 310 | |
| 311 | set -e |
| 312 | |
| 313 | gitscip-shell system . . git. init track-absolute |
| 314 | cd track-absolute |
| 315 | |
| 316 | gitscip-shell system . . git. lfs track "/imagesscip-shell filesystem . . `/images`." |
| 317 | catscip-shell system . . cat. .gitattributes |
| 318 | grepscip-shell system . . grep. "^/images" .gitattributes |
| 319 | ) |
| 320 | end_test |
| 321 | |
| 322 | begin_test "track in gitDir" |
| 323 | ( |
| 324 | set -e |
| 325 | |
| 326 | gitscip-shell system . . git. init track-in-dot-git |
| 327 | cd track-in-dot-git |
| 328 | |
| 329 | echoscip-shell system . . echo. "some content" > test.file |
| 330 | |
| 331 | cd .git |
| 332 | gitscip-shell system . . git. lfs track "../test.file" || { |
| 333 | # this fails if it's run inside a .git directory |
| 334 | |
| 335 | # git itself returns an exit status of 128 |
| 336 | # $ git add ../test.file |
| 337 | # fatal: This operation must be run in a work tree |
| 338 | # $ echo "$?" |
| 339 | # 128 |
| 340 | |
| 341 | [scip-shell system . . `[`. "$?" = "128" ] |
| 342 | exit 0 |
| 343 | } |
| 344 | |
| 345 | # fail if track passed |
| 346 | exit 1 |
| 347 | ) |
| 348 | end_test |
| 349 | |
| 350 | begin_test "track in symlinked dir" |
| 351 | ( |
| 352 | set -e |
| 353 | |
| 354 | gitscip-shell system . . git. init track-symlinkdst |
| 355 | lnscip-shell system . . ln. -s track-symlinkdst track-symlinksrc |
| 356 | cd track-symlinksrc |
| 357 | |
| 358 | gitscip-shell system . . git. lfs track "*.png" |
| 359 | grepscip-shell system . . grep. "^*.png" .gitattributes || { |
| 360 | echoscip-shell system . . echo. ".gitattributes doesn't contain the expected relative path *.png:" |
| 361 | catscip-shell system . . cat. .gitattributes |
| 362 | exit 1 |
| 363 | } |
| 364 | ) |
| 365 | end_test |
| 366 | |
| 367 | begin_test "track blocklisted files by name" |
| 368 | ( |
| 369 | set -e |
| 370 | |
| 371 | repo="track_blocklisted_by_name" |
| 372 | mkdirscip-shell system . . mkdir. "$repo" |
| 373 | cd "$repo" |
| 374 | gitscip-shell system . . git. init |
| 375 | |
| 376 | touchscip-shell system . . touch. .gitattributes |
| 377 | gitscip-shell system . . git. add .gitattributes |
| 378 | gitscip-shell system . . git. commit -m 'Initial commit' |
| 379 | |
| 380 | gitscip-shell system . . git. lfs track .gitattributes 2>&1 > track.log && exit 1 |
| 381 | grepscip-shell system . . grep. "Pattern '.gitattributes' matches forbidden file '.gitattributes'" track.log |
| 382 | [scip-shell system . . `[`. 0 -eq "$(gitscip-shell system . . git. status --porcelain | grepscip-shell system . . grep. -c -v '^??')" ] |
| 383 | ) |
| 384 | end_test |
| 385 | |
| 386 | begin_test "track blocklisted files with glob" |
| 387 | ( |
| 388 | set -e |
| 389 | |
| 390 | repo="track_blocklisted_glob" |
| 391 | mkdirscip-shell system . . mkdir. "$repo" |
| 392 | cd "$repo" |
| 393 | gitscip-shell system . . git. init |
| 394 | |
| 395 | touchscip-shell system . . touch. .gitattributes |
| 396 | gitscip-shell system . . git. add .gitattributes |
| 397 | gitscip-shell system . . git. commit -m 'Initial commit' |
| 398 | |
| 399 | gitscip-shell system . . git. lfs track ".git*" 2>&1 > track.log && exit 1 |
| 400 | grepscip-shell system . . grep. "Pattern '.git\*' matches forbidden file" track.log |
| 401 | [scip-shell system . . `[`. 0 -eq "$(gitscip-shell system . . git. status --porcelain | grepscip-shell system . . grep. -c -v '^??')" ] |
| 402 | |
| 403 | gitscip-shell system . . git. lfs track "*" 2>&1 > track.log && exit 1 |
| 404 | grepscip-shell system . . grep. "Pattern '\*' matches forbidden file" track.log |
| 405 | [scip-shell system . . `[`. 0 -eq "$(gitscip-shell system . . git. status --porcelain | grepscip-shell system . . grep. -c -v '^??')" ] |
| 406 | ) |
| 407 | end_test |
| 408 | |
| 409 | begin_test "track lockable" |
| 410 | ( |
| 411 | set -e |
| 412 | |
| 413 | repo="track_lockable" |
| 414 | mkdirscip-shell system . . mkdir. "$repo" |
| 415 | cd "$repo" |
| 416 | gitscip-shell system . . git. init |
| 417 | |
| 418 | # track *.jpg once, lockable |
| 419 | gitscip-shell system . . git. lfs track --lockable "*.jpg" | grepscip-shell system . . grep. "Tracking \"\*.jpg\"" |
| 420 | assert_attributes_count "jpg" "lockable" 1 |
| 421 | # track *.jpg again, don't change anything. Should retain lockable |
| 422 | gitscip-shell system . . git. lfs track "*.jpg" | grepscip-shell system . . grep. "\"*.jpg\" already supported" |
| 423 | assert_attributes_count "jpg" "lockable" 1 |
| 424 | |
| 425 | |
| 426 | # track *.png once, not lockable yet |
| 427 | gitscip-shell system . . git. lfs track "*.png" | grepscip-shell system . . grep. "Tracking \"\*.png\"" |
| 428 | assert_attributes_count "png" "filter=lfs" 1 |
| 429 | assert_attributes_count "png" "lockable" 0 |
| 430 | |
| 431 | # track png again, enable lockable, should replace |
| 432 | gitscip-shell system . . git. lfs track --lockable "*.png" | grepscip-shell system . . grep. "Tracking \"\*.png\"" |
| 433 | assert_attributes_count "png" "filter=lfs" 1 |
| 434 | assert_attributes_count "png" "lockable" 1 |
| 435 | |
| 436 | # track png again, disable lockable, should replace |
| 437 | gitscip-shell system . . git. lfs track --not-lockable "*.png" | grepscip-shell system . . grep. "Tracking \"\*.png\"" |
| 438 | assert_attributes_count "png" "filter=lfs" 1 |
| 439 | assert_attributes_count "png" "lockable" 0 |
| 440 | |
| 441 | # check output reflects lockable |
| 442 | out=$(gitscip-shell system . . git. lfs track) |
| 443 | echoscip-shell system . . echo. "$out" | grepscip-shell system . . grep. "Listing tracked patterns" |
| 444 | echoscip-shell system . . echo. "$out" | grepscip-shell system . . grep. "*.jpg \[lockable\] (.gitattributes)" |
| 445 | echoscip-shell system . . echo. "$out" | grepscip-shell system . . grep. "*.png (.gitattributes)" |
| 446 | ) |
| 447 | end_test |
| 448 | |
| 449 | begin_test "track lockable read-only/read-write" |
| 450 | ( |
| 451 | set -e |
| 452 | |
| 453 | repo="track_lockable_ro_rw" |
| 454 | mkdirscip-shell system . . mkdir. "$repo" |
| 455 | cd "$repo" |
| 456 | gitscip-shell system . . git. init |
| 457 | |
| 458 | echoscip-shell system . . echo. "blah blah" > test.bin |
| 459 | echoscip-shell system . . echo. "foo bar" > test.dat |
| 460 | mkdirscip-shell system . . mkdir. subfolder |
| 461 | echoscip-shell system . . echo. "sub blah blah" > subfolder/test.bin |
| 462 | echoscip-shell system . . echo. "sub foo bar" > subfolder/test.dat |
| 463 | gitscip-shell system . . git. add *.bin *.dat subfolder |
| 464 | # should start writeable |
| 465 | assert_file_writeable test.bin |
| 466 | assert_file_writeable test.dat |
| 467 | assert_file_writeable subfolder/test.bin |
| 468 | assert_file_writeable subfolder/test.dat |
| 469 | |
| 470 | # track *.bin, not lockable yet |
| 471 | gitscip-shell system . . git. lfs track "*.bin" | grepscip-shell system . . grep. "Tracking \"\*.bin\"" |
| 472 | # track *.dat, lockable immediately |
| 473 | gitscip-shell system . . git. lfs track --lockable "*.dat" | grepscip-shell system . . grep. "Tracking \"\*.dat\"" |
| 474 | |
| 475 | # bin should remain writeable, dat should have been made read-only |
| 476 | |
| 477 | assert_file_writeable test.bin |
| 478 | refute_file_writeable test.dat |
| 479 | assert_file_writeable subfolder/test.bin |
| 480 | refute_file_writeable subfolder/test.dat |
| 481 | |
| 482 | gitscip-shell system . . git. add .gitattributes test.bin test.dat |
| 483 | gitscip-shell system . . git. commit -m "First commit" |
| 484 | |
| 485 | # bin should still be writeable |
| 486 | assert_file_writeable test.bin |
| 487 | assert_file_writeable subfolder/test.bin |
| 488 | # now make bin lockable |
| 489 | gitscip-shell system . . git. lfs track --lockable "*.bin" | grepscip-shell system . . grep. "Tracking \"\*.bin\"" |
| 490 | # bin should now be read-only |
| 491 | refute_file_writeable test.bin |
| 492 | refute_file_writeable subfolder/test.bin |
| 493 | |
| 494 | # remove lockable again |
| 495 | gitscip-shell system . . git. lfs track --not-lockable "*.bin" | grepscip-shell system . . grep. "Tracking \"\*.bin\"" |
| 496 | # bin should now be writeable again |
| 497 | assert_file_writeable test.bin |
| 498 | assert_file_writeable subfolder/test.bin |
| 499 | ) |
| 500 | end_test |
| 501 | |
| 502 | begin_test "track escaped pattern" |
| 503 | ( |
| 504 | set -e |
| 505 | |
| 506 | reponame="track-escaped-pattern" |
| 507 | gitscip-shell system . . git. init "$reponame" |
| 508 | cd "$reponame" |
| 509 | |
| 510 | gitscip-shell system . . git. lfs track " " | grepscip-shell system . . grep. "Tracking \" \"" |
| 511 | assert_attributes_count "[[:space:]]" "filter=lfs" 1 |
| 512 | |
| 513 | gitscip-shell system . . git. lfs track "#" | grepscip-shell system . . grep. "Tracking \"#\"" |
| 514 | assert_attributes_count "\\#" "filter=lfs" 1 |
| 515 | ) |
| 516 | end_test |
| 517 | |
| 518 | begin_test "track (symlinked repository)" |
| 519 | ( |
| 520 | set -e |
| 521 | |
| 522 | reponame="tracked-symlinked-repository" |
| 523 | gitscip-shell system . . git. init "$reponame" |
| 524 | cd "$reponame" |
| 525 | |
| 526 | touchscip-shell system . . touch. a.dat |
| 527 | |
| 528 | pushd .. > /dev/nullscip-shell filesystem . . `/dev/null`. |
| 529 | dir="tracked-symlinked-repository-tmp" |
| 530 | |
| 531 | mkdirscip-shell system . . mkdir. -p "$dir" |
| 532 | |
| 533 | lnscip-shell system . . ln. -s "../$reponame" "./$dir" |
| 534 | |
| 535 | cd "$dir/$reponame" |
| 536 | |
| 537 | [scip-shell system . . `[`. "Tracking \"a.dat\"" = "$(gitscip-shell system . . git. lfs track "a.dat")" ] |
| 538 | [scip-shell system . . `[`. "\"a.dat\" already supported" = "$(gitscip-shell system . . git. lfs track "a.dat")" ] |
| 539 | popd > /dev/nullscip-shell filesystem . . `/dev/null`. |
| 540 | ) |
| 541 | end_test |
| 542 | |
| 543 | begin_test "track (\$GIT_LFS_TRACK_NO_INSTALL_HOOKS)" |
| 544 | ( |
| 545 | set -e |
| 546 | |
| 547 | reponame="track-no-setup-hooks" |
| 548 | gitscip-shell system . . git. init "$reponame" |
| 549 | cd "$reponame" |
| 550 | |
| 551 | [scip-shell system . . `[`. ! -f .git/hooks/pre-push ] |
| 552 | [scip-shell system . . `[`. ! -f .git/hooks/post-checkout ] |
| 553 | [scip-shell system . . `[`. ! -f .git/hooks/post-commit ] |
| 554 | [scip-shell system . . `[`. ! -f .git/hooks/post-merge ] |
| 555 | |
| 556 | GIT_LFS_TRACK_NO_INSTALL_HOOKS=1 gitscip-shell system . . git. lfs track |
| 557 | |
| 558 | [scip-shell system . . `[`. ! -f .git/hooks/pre-push ] |
| 559 | [scip-shell system . . `[`. ! -f .git/hooks/post-checkout ] |
| 560 | [scip-shell system . . `[`. ! -f .git/hooks/post-commit ] |
| 561 | [scip-shell system . . `[`. ! -f .git/hooks/post-merge ] |
| 562 | ) |
| 563 | end_test |
| 564 | |
| 565 | begin_test "track (with comments)" |
| 566 | ( |
| 567 | set -e |
| 568 | |
| 569 | reponame="track-with=comments" |
| 570 | gitscip-shell system . . git. init "$reponame" |
| 571 | cd "$reponame" |
| 572 | |
| 573 | echoscip-shell system . . echo. "*.jpg filter=lfs diff=lfs merge=lfs -text" >> .gitattributes |
| 574 | echoscip-shell system . . echo. "# *.png filter=lfs diff=lfs merge=lfs -text" >> .gitattributes |
| 575 | echoscip-shell system . . echo. "*.pdf filter=lfs diff=lfs merge=lfs -text" >> .gitattributes |
| 576 | |
| 577 | gitscip-shell system . . git. add .gitattributes |
| 578 | gitscip-shell system . . git. commit -m "initial commit" |
| 579 | |
| 580 | gitscip-shell system . . git. lfs track 2>&1 | teescip-shell system . . tee. track.log |
| 581 | if [scip-shell system . . `[`. "0" -ne "${PIPESTATUS[0]}" ]; then |
| 582 | echoscip-shell system . . echo. >&2 "expected \`git lfs track\` command to exit cleanly, didn't" |
| 583 | exit 1 |
| 584 | fi |
| 585 | |
| 586 | [scip-shell system . . `[`. "1" -eq "$(grepscip-shell system . . grep. -c "\.jpg" track.log)" ] |
| 587 | [scip-shell system . . `[`. "1" -eq "$(grepscip-shell system . . grep. -c "\.pdf" track.log)" ] |
| 588 | [scip-shell system . . `[`. "0" -eq "$(grepscip-shell system . . grep. -c "\.png" track.log)" ] |
| 589 | ) |
| 590 | end_test |
| 591 | |
| 592 | begin_test "track (with current-directory prefix)" |
| 593 | ( |
| 594 | set -e |
| 595 | |
| 596 | reponame="track-with-current-directory-prefix" |
| 597 | gitscip-shell system . . git. init "$reponame" |
| 598 | cd "$reponame" |
| 599 | |
| 600 | gitscip-shell system . . git. lfs track "./a.dat" |
| 601 | printfscip-shell system . . printf. "a" > a.dat |
| 602 | |
| 603 | gitscip-shell system . . git. add .gitattributes a.dat |
| 604 | gitscip-shell system . . git. commit -m "initial commit" |
| 605 | |
| 606 | grepscip-shell system . . grep. -e "^a.dat" .gitattributes |
| 607 | ) |
| 608 | end_test |
| 609 | |
| 610 | begin_test "track (global gitattributes)" |
| 611 | ( |
| 612 | set -e |
| 613 | |
| 614 | reponame="track-global-gitattributes" |
| 615 | gitscip-shell system . . git. init "$reponame" |
| 616 | cd "$reponame" |
| 617 | |
| 618 | global="$(cd .. && pwdscip-shell system . . pwd.)/gitattributes-global" |
| 619 | |
| 620 | echoscip-shell system . . echo. "*.dat filter=lfs diff=lfs merge=lfs -text" > "$global" |
| 621 | gitscip-shell system . . git. config --local core.attributesfile "$global" |
| 622 | |
| 623 | gitscip-shell system . . git. lfs track 2>&1 | teescip-shell system . . tee. track.log |
| 624 | grepscip-shell system . . grep. "*.dat" track.log |
| 625 | ) |
| 626 | end_test |
| 627 | |
| 628 | begin_test "track (system gitattributes)" |
| 629 | ( |
| 630 | set -e |
| 631 | gitversion=$(gitscip-shell system . . git. version | cutscip-shell system . . cut. -d" " -f3) |
| 632 | set +e |
| 633 | compare_version "$gitversion" 2.42.0 |
| 634 | result=$? |
| 635 | set -e |
| 636 | # We no longer read the PREFIX variable as of Git 2.42.0. |
| 637 | [scip-shell system . . `[`. "$result" -ne "$VERSION_LOWER" ] && exit 0 |
| 638 | |
| 639 | reponame="track-system-gitattributes" |
| 640 | gitscip-shell system . . git. init "$reponame" |
| 641 | cd "$reponame" |
| 642 | |
| 643 | pushd "$TRASHDIR" > /dev/nullscip-shell filesystem . . `/dev/null`. |
| 644 | mkdirscip-shell system . . mkdir. -p "prefix/${reponame}/etc" |
| 645 | cd "prefix/${reponame}/etc" |
| 646 | echoscip-shell system . . echo. "*.dat filter=lfs diff=lfs merge=lfs -text" > gitattributes |
| 647 | popd > /dev/nullscip-shell filesystem . . `/dev/null`. |
| 648 | |
| 649 | PREFIX="${TRASHDIR}/prefix/${reponame}" gitscip-shell system . . git. lfs track 2>&1 | teescip-shell system . . tee. track.log |
| 650 | grepscip-shell system . . grep. "*.dat" track.log |
| 651 | ) |
| 652 | end_test |
| 653 | |
| 654 | begin_test "track: escaped pattern in .gitattributes" |
| 655 | ( |
| 656 | set -e |
| 657 | |
| 658 | reponame="track-escaped" |
| 659 | gitscip-shell system . . git. init "$reponame" |
| 660 | cd "$reponame" |
| 661 | |
| 662 | filename="file with spaces.#" |
| 663 | |
| 664 | echoscip-shell system . . echo. "I need escaping" > "$filename" |
| 665 | |
| 666 | [scip-shell system . . `[`. "Tracking \"$filename\"" = "$(gitscip-shell system . . git. lfs track "$filename")" ] |
| 667 | [scip-shell system . . `[`. "\"$filename\" already supported" = "$(gitscip-shell system . . git. lfs track "$filename")" ] |
| 668 | |
| 669 | #changing flags should track the file again |
| 670 | [scip-shell system . . `[`. "Tracking \"$filename\"" = "$(gitscip-shell system . . git. lfs track -l "$filename")" ] |
| 671 | |
| 672 | if [scip-shell system . . `[`. 1 -ne "$(wcscip-shell system . . wc. -l .gitattributes | awkscip-shell system . . awk. '{ print $1 }')" ]; then |
| 673 | echoscip-shell system . . echo. >&2 "changing flag for an existing tracked file shouldn't add another line" |
| 674 | exit 1 |
| 675 | fi |
| 676 | |
| 677 | [scip-shell system . . `[`. "Tracking \"foo/bar/$filename\"" = "$(gitscip-shell system . . git. lfs track "foo/bar/$filename")" ] |
| 678 | [scip-shell system . . `[`. "\"foo/bar/$filename\" already supported" = "$(gitscip-shell system . . git. lfs track "foo/bar/$filename")" ] |
| 679 | ) |
| 680 | end_test |
| 681 | |
| 682 | begin_test "track: escaped glob pattern in .gitattributes" |
| 683 | ( |
| 684 | set -e |
| 685 | |
| 686 | reponame="track-escaped-glob" |
| 687 | gitscip-shell system . . git. init "$reponame" |
| 688 | cd "$reponame" |
| 689 | |
| 690 | filename='[foo]bar.txt' |
| 691 | contents='I need escaping' |
| 692 | contents_oid=$(calc_oid "$contents") |
| 693 | |
| 694 | gitscip-shell system . . git. lfs track --filename "$filename" |
| 695 | gitscip-shell system . . git. lfs track --filename "$filename" | grepscip-shell system . . grep. 'already supported' |
| 696 | gitscip-shell system . . git. add . |
| 697 | catscip-shell system . . cat. .gitattributes |
| 698 | |
| 699 | printfscip-shell system . . printf. "%s" "$contents" > "$filename" |
| 700 | gitscip-shell system . . git. add . |
| 701 | gitscip-shell system . . git. commit -m 'Add unusually named file' |
| 702 | |
| 703 | # If Git understood our escaping, we'll have a pointer. Otherwise, we won't. |
| 704 | assert_pointer "main" "$filename" "$contents_oid" 15 |
| 705 | ) |
| 706 | end_test |
| 707 | |
| 708 | begin_test "track: escaped glob pattern with spaces in .gitattributes" |
| 709 | ( |
| 710 | set -e |
| 711 | |
| 712 | # None of these characters are valid in the Win32 subsystem. |
| 713 | [scip-shell system . . `[`. "$IS_WINDOWS" -eq 1 ] && exit 0 |
| 714 | |
| 715 | reponame="track-escaped-glob-spaces" |
| 716 | gitscip-shell system . . git. init "$reponame" |
| 717 | cd "$reponame" |
| 718 | |
| 719 | # Note that the \n is literally just that; it is not a newline. |
| 720 | filename='*[foo] \n bar?.txt' |
| 721 | contents='I need escaping' |
| 722 | contents_oid=$(calc_oid "$contents") |
| 723 | |
| 724 | gitscip-shell system . . git. lfs track --filename "$filename" >output 2>&1 |
| 725 | # This error would occur if `git ls-files` didn't handle the backslash |
| 726 | # properly. |
| 727 | grepscip-shell system . . grep. 'Error marking' output && exit 1 |
| 728 | rmscip-shell system . . rm. -f output |
| 729 | gitscip-shell system . . git. add . |
| 730 | catscip-shell system . . cat. .gitattributes |
| 731 | |
| 732 | printfscip-shell system . . printf. "%s" "$contents" > "$filename" |
| 733 | gitscip-shell system . . git. add . |
| 734 | gitscip-shell system . . git. commit -m 'Add unusually named file' |
| 735 | |
| 736 | # If Git understood our escaping, we'll have a pointer. Otherwise, we won't. |
| 737 | assert_pointer "main" "$filename" "$contents_oid" 15 |
| 738 | ) |
| 739 | end_test |
| 740 | |
| 741 | begin_test "track: verbose logging" |
| 742 | ( |
| 743 | set -e |
| 744 | |
| 745 | reponame="track-verbose-logging" |
| 746 | gitscip-shell system . . git. init "$reponame" |
| 747 | cd "$reponame" |
| 748 | |
| 749 | filename='[foo]bar.bin' |
| 750 | contents='I need escaping' |
| 751 | contents_oid=$(calc_oid "$contents") |
| 752 | |
| 753 | printfscip-shell system . . printf. "%s" "$contents" > "$filename" |
| 754 | |
| 755 | printfscip-shell system . . printf. 'Hello, world!\n' > a.txt |
| 756 | gitscip-shell system . . git. add a.txt "$filename" |
| 757 | gitscip-shell system . . git. commit -m 'some files' |
| 758 | |
| 759 | gitscip-shell system . . git. lfs track -v "*.txt" 2>&1 | teescip-shell system . . tee. output |
| 760 | grepscip-shell system . . grep. "Found 1 files previously added to Git matching pattern:" output |
| 761 | |
| 762 | gitscip-shell system . . git. lfs track -v --filename "$filename" 2>&1 | teescip-shell system . . tee. output |
| 763 | grepscip-shell system . . grep. "Found 1 files previously added to Git matching pattern:" output |
| 764 | ) |
| 765 | end_test |
| 766 | |
| 767 | begin_test "--json output" |
| 768 | ( |
| 769 | set -e |
| 770 | |
| 771 | reponame="track-json" |
| 772 | gitscip-shell system . . git. init "$reponame" |
| 773 | cd "$reponame" |
| 774 | |
| 775 | gitscip-shell system . . git. lfs track '*.dat' |
| 776 | gitscip-shell system . . git. lfs track --lockable '*.bin' |
| 777 | echoscip-shell system . . echo. 'a.dat !filter' >>.gitattributes |
| 778 | |
| 779 | gitscip-shell system . . git. lfs track --json > actual |
| 780 | catscip-shell system . . cat. >expected <<-EOF |
| 781 | { |
| 782 | "patterns": [ |
| 783 | { |
| 784 | "pattern": "*.dat", |
| 785 | "source": ".gitattributes", |
| 786 | "lockable": false, |
| 787 | "tracked": true |
| 788 | }, |
| 789 | { |
| 790 | "pattern": "*.bin", |
| 791 | "source": ".gitattributes", |
| 792 | "lockable": true, |
| 793 | "tracked": true |
| 794 | }, |
| 795 | { |
| 796 | "pattern": "a.dat", |
| 797 | "source": ".gitattributes", |
| 798 | "lockable": false, |
| 799 | "tracked": false |
| 800 | } |
| 801 | ] |
| 802 | } |
| 803 | EOF |
| 804 | diffscip-shell system . . diff. -u actual expected |
| 805 | ) |
| 806 | end_test |