| 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | . "$(dirname "$0")/testlib.sh" |
| 4 | |
| 5 | begin_test "pre-push with good ref" |
| 6 | ( |
| 7 | set -e |
| 8 | reponame="pre-push-main-branch-required" |
| 9 | setup_remote_repo "$reponame" |
| 10 | clone_repo "$reponame" "$reponame" |
| 11 | |
| 12 | git config "lfs.$(repo_endpoint "$GITSERVER" "$reponame").locksverify" false |
| 13 | git lfs track "*.dat" |
| 14 | echo "hi" > a.dat |
| 15 | git add .gitattributes a.dat |
| 16 | git commit -m "add a.dat" |
| 17 | |
| 18 | refute_server_object "$reponame" 98ea6e4f216f2fb4b69fff9b3a44842c38686ca685f3f55dc48c5d3fb1107be4 "refs/heads/main" |
| 19 | |
| 20 | # for some reason, using 'tee' and $PIPESTATUS does not work here |
| 21 | echo "refs/heads/main main refs/heads/main 0000000000000000000000000000000000000000" | |
| 22 | git lfs pre-push origin "$GITSERVER/$reponame" 2>&1 > push.log |
| 23 | |
| 24 | assert_server_object "$reponame" 98ea6e4f216f2fb4b69fff9b3a44842c38686ca685f3f55dc48c5d3fb1107be4 "refs/heads/main" |
| 25 | ) |
| 26 | end_test |
| 27 | |
| 28 | begin_test "pre-push with tracked ref" |
| 29 | ( |
| 30 | set -e |
| 31 | reponame="pre-push-tracked-branch-required" |
| 32 | setup_remote_repo "$reponame" |
| 33 | clone_repo "$reponame" "$reponame" |
| 34 | |
| 35 | git config "lfs.$(repo_endpoint "$GITSERVER" "$reponame").locksverify" false |
| 36 | git lfs track "*.dat" |
| 37 | echo "hi" > a.dat |
| 38 | git add .gitattributes a.dat |
| 39 | git commit -m "add a.dat" |
| 40 | |
| 41 | refute_server_object "$reponame" 98ea6e4f216f2fb4b69fff9b3a44842c38686ca685f3f55dc48c5d3fb1107be4 "refs/heads/tracked" |
| 42 | |
| 43 | # for some reason, using 'tee' and $PIPESTATUS does not work here |
| 44 | echo "refs/heads/main main refs/heads/tracked 0000000000000000000000000000000000000000" | |
| 45 | git lfs pre-push origin main 2>&1 > push.log |
| 46 | |
| 47 | assert_server_object "$reponame" 98ea6e4f216f2fb4b69fff9b3a44842c38686ca685f3f55dc48c5d3fb1107be4 "refs/heads/tracked" |
| 48 | ) |
| 49 | end_test |
| 50 | |
| 51 | begin_test "pre-push with bad ref" |
| 52 | ( |
| 53 | set -e |
| 54 | reponame="pre-push-other-branch-required" |
| 55 | setup_remote_repo "$reponame" |
| 56 | clone_repo "$reponame" "$reponame" |
| 57 | |
| 58 | git config "lfs.$(repo_endpoint "$GITSERVER" "$reponame").locksverify" false |
| 59 | git lfs track "*.dat" |
| 60 | echo "hi" > a.dat |
| 61 | git add .gitattributes a.dat |
| 62 | git commit -m "add a.dat" |
| 63 | |
| 64 | refute_server_object "$reponame" 98ea6e4f216f2fb4b69fff9b3a44842c38686ca685f3f55dc48c5d3fb1107be4 "refs/heads/other" |
| 65 | |
| 66 | # for some reason, using 'tee' and $PIPESTATUS does not work here |
| 67 | set +e |
| 68 | echo "refs/heads/main main refs/heads/main 0000000000000000000000000000000000000000" | |
| 69 | git lfs pre-push origin "$GITSERVER/$reponame" 2> push.log |
| 70 | pushcode=$? |
| 71 | set -e |
| 72 | |
| 73 | if [ "0" -eq "$pushcode" ]; then |
| 74 | echo "expected command to fail" |
| 75 | exit 1 |
| 76 | fi |
| 77 | |
| 78 | grep 'Expected ref "refs/heads/other", got "refs/heads/main"' push.log |
| 79 | |
| 80 | refute_server_object "$reponame" 98ea6e4f216f2fb4b69fff9b3a44842c38686ca685f3f55dc48c5d3fb1107be4 "refs/heads/other" |
| 81 | ) |
| 82 | end_test |
| 83 | |
| 84 | begin_test "pre-push" |
| 85 | ( |
| 86 | set -e |
| 87 | |
| 88 | reponame="$(basename "$0" ".sh")" |
| 89 | setup_remote_repo "$reponame" |
| 90 | |
| 91 | clone_repo "$reponame" repo |
| 92 | git lfs track "*.dat" |
| 93 | git add .gitattributes |
| 94 | git commit -m "add git attributes" |
| 95 | |
| 96 | git config "lfs.$(repo_endpoint $GITSERVER $reponame).locksverify" true |
| 97 | |
| 98 | echo "refs/heads/main main refs/heads/main 0000000000000000000000000000000000000000" | |
| 99 | git lfs pre-push origin "$GITSERVER/$reponame" | |
| 100 | tee push.log |
| 101 | # no output if nothing to do |
| 102 | [ "$(du -k push.log | cut -f 1)" == "0" ] |
| 103 | |
| 104 | git lfs track "*.dat" |
| 105 | echo "hi" > hi.dat |
| 106 | git add hi.dat |
| 107 | git commit -m "add hi.dat" |
| 108 | git show |
| 109 | |
| 110 | refute_server_object "$reponame" 98ea6e4f216f2fb4b69fff9b3a44842c38686ca685f3f55dc48c5d3fb1107be4 |
| 111 | |
| 112 | # push file to the git lfs server |
| 113 | echo "refs/heads/main main refs/heads/main 0000000000000000000000000000000000000000" | |
| 114 | git lfs pre-push origin "$GITSERVER/$reponame" 2>&1 | |
| 115 | tee push.log |
| 116 | grep "Uploading LFS objects: 100% (1/1), 3 B" push.log |
| 117 | |
| 118 | assert_server_object "$reponame" 98ea6e4f216f2fb4b69fff9b3a44842c38686ca685f3f55dc48c5d3fb1107be4 |
| 119 | ) |
| 120 | end_test |
| 121 | |
| 122 | begin_test "pre-push dry-run" |
| 123 | ( |
| 124 | set -e |
| 125 | |
| 126 | reponame="$(basename "$0" ".sh")-dry-run" |
| 127 | setup_remote_repo "$reponame" |
| 128 | |
| 129 | clone_repo "$reponame" repo-dry-run |
| 130 | git lfs track "*.dat" |
| 131 | git add .gitattributes |
| 132 | git commit -m "add git attributes" |
| 133 | |
| 134 | git config "lfs.$(repo_endpoint $GITSERVER $reponame).locksverify" true |
| 135 | |
| 136 | echo "refs/heads/main main refs/heads/main 0000000000000000000000000000000000000000" | |
| 137 | git lfs pre-push --dry-run origin "$GITSERVER/$reponame" | |
| 138 | tee push.log |
| 139 | |
| 140 | [ "" = "$(cat push.log)" ] |
| 141 | |
| 142 | git lfs track "*.dat" |
| 143 | echo "dry" > hi.dat |
| 144 | git add hi.dat |
| 145 | git commit -m "add hi.dat" |
| 146 | git show |
| 147 | |
| 148 | refute_server_object "$reponame" 2840e0eafda1d0760771fe28b91247cf81c76aa888af28a850b5648a338dc15b |
| 149 | |
| 150 | echo "refs/heads/main main refs/heads/main 0000000000000000000000000000000000000000" | |
| 151 | git lfs pre-push --dry-run origin "$GITSERVER/$reponame" | |
| 152 | tee push.log |
| 153 | grep "push 2840e0eafda1d0760771fe28b91247cf81c76aa888af28a850b5648a338dc15b => hi.dat" push.log |
| 154 | cat push.log |
| 155 | [ `wc -l < push.log` = 1 ] |
| 156 | |
| 157 | refute_server_object "$reponame" 2840e0eafda1d0760771fe28b91247cf81c76aa888af28a850b5648a338dc15b |
| 158 | ) |
| 159 | end_test |
| 160 | |
| 161 | begin_test "pre-push skip-push" |
| 162 | ( |
| 163 | set -e |
| 164 | |
| 165 | reponame="$(basename "$0" ".sh")-skip-push" |
| 166 | setup_remote_repo "$reponame" |
| 167 | |
| 168 | clone_repo "$reponame" repo-skip-push |
| 169 | git lfs track "*.dat" |
| 170 | git add .gitattributes |
| 171 | git commit -m "add git attributes" |
| 172 | |
| 173 | git config "lfs.$(repo_endpoint $GITSERVER $reponame).locksverify" true |
| 174 | |
| 175 | echo "refs/heads/main main refs/heads/main 0000000000000000000000000000000000000000" | |
| 176 | GIT_LFS_SKIP_PUSH=true git lfs pre-push origin "$GITSERVER/$reponame" | |
| 177 | tee push.log |
| 178 | |
| 179 | [ "" = "$(cat push.log)" ] |
| 180 | |
| 181 | git lfs track "*.dat" |
| 182 | echo "dry" > hi.dat |
| 183 | git add hi.dat |
| 184 | git commit -m "add hi.dat" |
| 185 | git show |
| 186 | |
| 187 | refute_server_object "$reponame" 2840e0eafda1d0760771fe28b91247cf81c76aa888af28a850b5648a338dc15b |
| 188 | |
| 189 | echo "refs/heads/main main refs/heads/main 0000000000000000000000000000000000000000" | |
| 190 | GIT_LFS_SKIP_PUSH=true git lfs pre-push origin "$GITSERVER/$reponame" | |
| 191 | tee push.log |
| 192 | |
| 193 | [ "" = "$(cat push.log)" ] |
| 194 | |
| 195 | refute_server_object "$reponame" 2840e0eafda1d0760771fe28b91247cf81c76aa888af28a850b5648a338dc15b |
| 196 | ) |
| 197 | end_test |
| 198 | |
| 199 | begin_test "pre-push 307 redirects" |
| 200 | ( |
| 201 | set -e |
| 202 | |
| 203 | reponame="$(basename "$0" ".sh")" |
| 204 | setup_remote_repo "$reponame" |
| 205 | |
| 206 | clone_repo "$reponame" repo-307 |
| 207 | git lfs track "*.dat" |
| 208 | git add .gitattributes |
| 209 | git commit -m "add git attributes" |
| 210 | |
| 211 | # relative redirect |
| 212 | git config remote.origin.lfsurl "$GITSERVER/redirect307/rel/$reponame.git/info/lfs" |
| 213 | |
| 214 | git lfs track "*.dat" |
| 215 | echo "hi" > hi.dat |
| 216 | git add hi.dat |
| 217 | git commit -m "add hi.dat" |
| 218 | git show |
| 219 | |
| 220 | # push file to the git lfs server |
| 221 | echo "refs/heads/main main refs/heads/main 0000000000000000000000000000000000000000" | |
| 222 | git lfs pre-push origin "$GITSERVER/redirect307/rel/$reponame.git/info/lfs" 2>&1 | |
| 223 | tee push.log |
| 224 | grep "Uploading LFS objects: 100% (1/1), 3 B" push.log |
| 225 | |
| 226 | assert_server_object "$reponame" 98ea6e4f216f2fb4b69fff9b3a44842c38686ca685f3f55dc48c5d3fb1107be4 |
| 227 | |
| 228 | # absolute redirect |
| 229 | git config remote.origin.lfsurl "$GITSERVER/redirect307/abs/$reponame.git/info/lfs" |
| 230 | |
| 231 | echo "hi" > hi2.dat |
| 232 | git add hi2.dat |
| 233 | git commit -m "add hi2.dat" |
| 234 | git show |
| 235 | |
| 236 | # push file to the git lfs server |
| 237 | echo "refs/heads/main main refs/heads/main 0000000000000000000000000000000000000000" | |
| 238 | git lfs pre-push origin "$GITSERVER/redirect307/abs/$reponame.git/info/lfs" 2>&1 | |
| 239 | tee push.log |
| 240 | grep "Uploading LFS objects: 100% (1/1), 3 B" push.log |
| 241 | ) |
| 242 | end_test |
| 243 | |
| 244 | begin_test "pre-push with existing object" |
| 245 | ( |
| 246 | set -e |
| 247 | |
| 248 | reponame="pre-push-existing-object" |
| 249 | setup_remote_repo "$reponame" |
| 250 | clone_repo "$reponame" "$reponame" |
| 251 | |
| 252 | echo "existing" > existing.dat |
| 253 | git add existing.dat |
| 254 | git commit -m "add existing dat" |
| 255 | |
| 256 | git lfs track "*.dat" |
| 257 | echo "new" > new.dat |
| 258 | git add new.dat |
| 259 | git add .gitattributes |
| 260 | git commit -m "add new file through git lfs" |
| 261 | |
| 262 | # push file to the git lfs server |
| 263 | echo "refs/heads/main main refs/heads/main 0000000000000000000000000000000000000000" | |
| 264 | git lfs pre-push origin "$GITSERVER/$reponame" 2>&1 | |
| 265 | tee push.log |
| 266 | grep "Uploading LFS objects: 100% (1/1), 4 B" push.log |
| 267 | |
| 268 | # now the file exists |
| 269 | assert_server_object "$reponame" 7aa7a5359173d05b63cfd682e3c38487f3cb4f7f1d60659fe59fab1505977d4c |
| 270 | ) |
| 271 | end_test |
| 272 | |
| 273 | begin_test "pre-push with existing object (untracked)" |
| 274 | ( |
| 275 | set -e |
| 276 | |
| 277 | reponame="pre-push-existing-object-untracked" |
| 278 | setup_remote_repo "$reponame" |
| 279 | clone_repo "$reponame" "$reponame" |
| 280 | |
| 281 | echo "$(pointer "7aa7a5359173d05b63cfd682e3c38487f3cb4f7f1d60659fe59fab1505977d4c" 4)" > new.dat |
| 282 | git add new.dat |
| 283 | git commit -m "add new pointer" |
| 284 | mkdir -p .git/lfs/objects/7a/a7 |
| 285 | echo "new" > .git/lfs/objects/7a/a7/7aa7a5359173d05b63cfd682e3c38487f3cb4f7f1d60659fe59fab1505977d4c |
| 286 | |
| 287 | # push file to the git lfs server |
| 288 | echo "refs/heads/main main refs/heads/main 0000000000000000000000000000000000000000" | |
| 289 | git lfs pre-push origin "$GITSERVER/$reponame" 2>&1 | |
| 290 | tee push.log |
| 291 | grep "Uploading LFS objects: 100% (1/1), 4 B" push.log |
| 292 | |
| 293 | # now the file exists |
| 294 | assert_server_object "$reponame" 7aa7a5359173d05b63cfd682e3c38487f3cb4f7f1d60659fe59fab1505977d4c |
| 295 | ) |
| 296 | end_test |
| 297 | |
| 298 | begin_test "pre-push reject missing object" |
| 299 | ( |
| 300 | set -e |
| 301 | |
| 302 | reponame="pre-push-reject-missing-object" |
| 303 | setup_remote_repo "$reponame" |
| 304 | clone_repo "$reponame" "$reponame" |
| 305 | |
| 306 | oid="7aa7a5359173d05b63cfd682e3c38487f3cb4f7f1d60659fe59fab1505977d4c" |
| 307 | |
| 308 | echo "$(pointer "$oid" 4)" > new.dat |
| 309 | git add new.dat |
| 310 | git commit -m "add new pointer" |
| 311 | |
| 312 | # assert that push fails |
| 313 | echo "refs/heads/main main refs/heads/main 0000000000000000000000000000000000000000" | |
| 314 | git lfs pre-push origin "$GITSERVER/$reponame" 2>&1 | |
| 315 | tee push.log |
| 316 | |
| 317 | if [ "2" -ne "${PIPESTATUS[1]}" ]; then |
| 318 | echo >&2 "fatal: expected 'git lfs pre-push origin $GITSERVER/$reponame' to fail ..." |
| 319 | exit 1 |
| 320 | fi |
| 321 | |
| 322 | grep "LFS upload failed:" push.log |
| 323 | grep " (missing) new.dat ($oid)" push.log |
| 324 | |
| 325 | refute_server_object "$reponame" "$oid" |
| 326 | ) |
| 327 | end_test |
| 328 | |
| 329 | begin_test "pre-push allow missing object (found on server)" |
| 330 | ( |
| 331 | # should permit push if files missing locally but are on server, shouldn't |
| 332 | # require client to have every file (prune) |
| 333 | set -e |
| 334 | |
| 335 | reponame="pre-push-allow-missing-object-found-on-server" |
| 336 | setup_remote_repo "$reponame" |
| 337 | clone_repo "$reponame" "$reponame" |
| 338 | |
| 339 | contents="common data" |
| 340 | contents_oid=$(calc_oid "$contents") |
| 341 | git lfs track "*.dat" |
| 342 | printf "%s" "$contents" > common1.dat |
| 343 | git add common1.dat |
| 344 | git add .gitattributes |
| 345 | git commit -m "add first file" |
| 346 | |
| 347 | # push file to the git lfs server |
| 348 | echo "refs/heads/main main refs/heads/main 0000000000000000000000000000000000000000" | |
| 349 | git lfs pre-push origin "$GITSERVER/$reponame" 2>&1 | |
| 350 | tee push.log |
| 351 | grep "Uploading LFS objects: 100% (1/1), 11 B" push.log |
| 352 | |
| 353 | # now the file exists |
| 354 | assert_server_object "$reponame" "$contents_oid" |
| 355 | |
| 356 | # create another commit referencing same oid, then delete local data & push |
| 357 | printf "%s" "$contents" > common2.dat |
| 358 | git add common2.dat |
| 359 | git commit -m "add second file, same content" |
| 360 | rm -rf .git/lfs/objects |
| 361 | echo "refs/heads/main main refs/heads/main 0000000000000000000000000000000000000000" | |
| 362 | git lfs pre-push origin "$GITSERVER/$reponame" 2>&1 | |
| 363 | tee push.log |
| 364 | |
| 365 | # make sure there were no errors reported |
| 366 | [ 0 -eq "$(grep -c -i 'Error' push.log)" ] |
| 367 | ) |
| 368 | end_test |
| 369 | |
| 370 | begin_test "pre-push allow missing object (lfs.allowincompletepush true)" |
| 371 | ( |
| 372 | set -e |
| 373 | |
| 374 | reponame="pre-push-allow-missing-object" |
| 375 | setup_remote_repo "$reponame" |
| 376 | clone_repo "$reponame" "$reponame" |
| 377 | |
| 378 | git lfs track "*.dat" |
| 379 | git add .gitattributes |
| 380 | git commit -m "initial commit" |
| 381 | |
| 382 | present="present" |
| 383 | present_oid="$(calc_oid "$present")" |
| 384 | printf "%s" "$present" > present.dat |
| 385 | |
| 386 | missing="missing" |
| 387 | missing_oid="$(calc_oid "$missing")" |
| 388 | printf "%s" "$missing" > missing.dat |
| 389 | |
| 390 | git add present.dat missing.dat |
| 391 | git commit -m "add objects" |
| 392 | |
| 393 | delete_local_object "$missing_oid" |
| 394 | |
| 395 | git config lfs.allowincompletepush true |
| 396 | |
| 397 | echo "refs/heads/main main refs/heads/main 0000000000000000000000000000000000000000" | |
| 398 | git lfs pre-push origin "$GITSERVER/$reponame" 2>&1 | |
| 399 | tee push.log |
| 400 | |
| 401 | if [ "0" -ne "${PIPESTATUS[1]}" ]; then |
| 402 | echo >&2 "fatal: expected 'git lfs pre-push origin $GITSERVER/$reponame' to succeed ..." |
| 403 | exit 1 |
| 404 | fi |
| 405 | |
| 406 | grep "LFS upload missing objects" push.log |
| 407 | grep " (missing) missing.dat ($missing_oid)" push.log |
| 408 | |
| 409 | assert_server_object "$reponame" "$present_oid" |
| 410 | refute_server_object "$reponame" "$missing_oid" |
| 411 | ) |
| 412 | end_test |
| 413 | |
| 414 | begin_test "pre-push reject missing object (lfs.allowincompletepush default)" |
| 415 | ( |
| 416 | set -e |
| 417 | |
| 418 | reponame="pre-push-reject-missing-object-default" |
| 419 | setup_remote_repo "$reponame" |
| 420 | clone_repo "$reponame" "$reponame" |
| 421 | |
| 422 | git lfs track "*.dat" |
| 423 | git add .gitattributes |
| 424 | git commit -m "initial commit" |
| 425 | |
| 426 | present="present" |
| 427 | present_oid="$(calc_oid "$present")" |
| 428 | printf "%s" "$present" > present.dat |
| 429 | |
| 430 | missing="missing" |
| 431 | missing_oid="$(calc_oid "$missing")" |
| 432 | printf "%s" "$missing" > missing.dat |
| 433 | |
| 434 | git add present.dat missing.dat |
| 435 | git commit -m "add objects" |
| 436 | |
| 437 | delete_local_object "$missing_oid" |
| 438 | |
| 439 | echo "refs/heads/main main refs/heads/main 0000000000000000000000000000000000000000" | |
| 440 | GIT_TRACE=1 git lfs pre-push origin "$GITSERVER/$reponame" 2>&1 | |
| 441 | tee push.log |
| 442 | |
| 443 | if [ "2" -ne "${PIPESTATUS[1]}" ]; then |
| 444 | echo >&2 "fatal: expected 'git lfs pre-push origin $GITSERVER/$reponame' to fail ..." |
| 445 | exit 1 |
| 446 | fi |
| 447 | |
| 448 | grep "tq: stopping batched queue, object \"$missing_oid\" missing locally and on remote" push.log |
| 449 | grep "LFS upload failed:" push.log |
| 450 | grep " (missing) missing.dat ($missing_oid)" push.log |
| 451 | |
| 452 | refute_server_object "$reponame" "$present_oid" |
| 453 | refute_server_object "$reponame" "$missing_oid" |
| 454 | ) |
| 455 | end_test |
| 456 | |
| 457 | begin_test "pre-push multiple branches" |
| 458 | ( |
| 459 | set -e |
| 460 | |
| 461 | reponame="$(basename "$0" ".sh")-multiple-branches" |
| 462 | setup_remote_repo "$reponame" |
| 463 | clone_repo "$reponame" "$reponame" |
| 464 | |
| 465 | |
| 466 | git lfs track "*.dat" 2>&1 | tee track.log |
| 467 | grep "Tracking \"\*.dat\"" track.log |
| 468 | |
| 469 | NUMFILES=6 |
| 470 | # generate content we'll use |
| 471 | for ((a=0; a < NUMFILES ; a++)) |
| 472 | do |
| 473 | content[$a]="filecontent$a" |
| 474 | oid[$a]=$(calc_oid "${content[$a]}") |
| 475 | done |
| 476 | |
| 477 | echo "[ |
| 478 | { |
| 479 | \"CommitDate\":\"$(get_date -10d)\", |
| 480 | \"Files\":[ |
| 481 | {\"Filename\":\"file1.dat\",\"Size\":${#content[0]}, \"Data\":\"${content[0]}\"}, |
| 482 | {\"Filename\":\"file2.dat\",\"Size\":${#content[1]}, \"Data\":\"${content[1]}\"}] |
| 483 | }, |
| 484 | { |
| 485 | \"NewBranch\":\"branch1\", |
| 486 | \"CommitDate\":\"$(get_date -5d)\", |
| 487 | \"Files\":[ |
| 488 | {\"Filename\":\"file2.dat\",\"Size\":${#content[2]}, \"Data\":\"${content[2]}\"}] |
| 489 | }, |
| 490 | { |
| 491 | \"ParentBranches\":[\"main\"], |
| 492 | \"NewBranch\":\"branch2\", |
| 493 | \"CommitDate\":\"$(get_date -5d)\", |
| 494 | \"Files\":[ |
| 495 | {\"Filename\":\"file3.dat\",\"Size\":${#content[3]}, \"Data\":\"${content[3]}\"}] |
| 496 | }, |
| 497 | { |
| 498 | \"ParentBranches\":[\"main\"], |
| 499 | \"NewBranch\":\"branch3\", |
| 500 | \"CommitDate\":\"$(get_date -2d)\", |
| 501 | \"Files\":[ |
| 502 | {\"Filename\":\"file1.dat\",\"Size\":${#content[4]}, \"Data\":\"${content[4]}\"}] |
| 503 | }, |
| 504 | { |
| 505 | \"ParentBranches\":[\"main\"], |
| 506 | \"NewBranch\":\"branch4\", |
| 507 | \"CommitDate\":\"$(get_date -1d)\", |
| 508 | \"Files\":[ |
| 509 | {\"Filename\":\"file4.dat\",\"Size\":${#content[5]}, \"Data\":\"${content[5]}\"}] |
| 510 | } |
| 511 | ]" | lfstest-testutils addcommits |
| 512 | |
| 513 | # make sure when called via git push all branches are updated |
| 514 | git push origin main branch1 branch2 branch3 branch4 |
| 515 | for ((a=0; a < NUMFILES ; a++)) |
| 516 | do |
| 517 | assert_server_object "$reponame" "${oid[$a]}" |
| 518 | done |
| 519 | |
| 520 | ) |
| 521 | end_test |
| 522 | |
| 523 | begin_test "pre-push with bad remote" |
| 524 | ( |
| 525 | set -e |
| 526 | |
| 527 | cd repo |
| 528 | |
| 529 | echo "refs/heads/main main refs/heads/main 0000000000000000000000000000000000000000" | |
| 530 | git lfs pre-push not-a-remote "$GITSERVER/$reponame" 2>&1 | |
| 531 | tee pre-push.log |
| 532 | grep "Invalid remote name" pre-push.log |
| 533 | ) |
| 534 | end_test |
| 535 | |
| 536 | begin_test "pre-push unfetched deleted remote branch & server GC" |
| 537 | ( |
| 538 | # point of this is to simulate the case where the local cache of the remote |
| 539 | # branch state contains a branch which has actually been deleted on the remote, |
| 540 | # the client just doesn't know yet (hasn't done 'git fetch origin --prune') |
| 541 | # If the server GC'd the objects that deleted branch contained, but they were |
| 542 | # referenced by a branch being pushed (earlier commit), push might assume it |
| 543 | # doesn't have to push it, but it does. Tests that we check the real remote refs |
| 544 | # before making an assumption about the diff we need to push |
| 545 | set -e |
| 546 | |
| 547 | reponame="$(basename "$0" ".sh")-server-deleted-branch-gc" |
| 548 | setup_remote_repo "$reponame" |
| 549 | clone_repo "$reponame" "$reponame" |
| 550 | |
| 551 | |
| 552 | git lfs track "*.dat" 2>&1 | tee track.log |
| 553 | grep "Tracking \"\*.dat\"" track.log |
| 554 | |
| 555 | NUMFILES=4 |
| 556 | # generate content we'll use |
| 557 | for ((a=0; a < NUMFILES ; a++)) |
| 558 | do |
| 559 | content[$a]="filecontent$a" |
| 560 | oid[$a]=$(calc_oid "${content[$a]}") |
| 561 | done |
| 562 | |
| 563 | echo "[ |
| 564 | { |
| 565 | \"CommitDate\":\"$(get_date -10d)\", |
| 566 | \"Files\":[ |
| 567 | {\"Filename\":\"file1.dat\",\"Size\":${#content[0]}, \"Data\":\"${content[0]}\"}, |
| 568 | {\"Filename\":\"file2.dat\",\"Size\":${#content[1]}, \"Data\":\"${content[1]}\"}] |
| 569 | }, |
| 570 | { |
| 571 | \"NewBranch\":\"branch-to-delete\", |
| 572 | \"CommitDate\":\"$(get_date -5d)\", |
| 573 | \"Files\":[ |
| 574 | {\"Filename\":\"file3.dat\",\"Size\":${#content[2]}, \"Data\":\"${content[2]}\"}] |
| 575 | }, |
| 576 | { |
| 577 | \"NewBranch\":\"branch-to-push-after\", |
| 578 | \"CommitDate\":\"$(get_date -2d)\", |
| 579 | \"Files\":[ |
| 580 | {\"Filename\":\"file4.dat\",\"Size\":${#content[3]}, \"Data\":\"${content[3]}\"}] |
| 581 | } |
| 582 | ]" | lfstest-testutils addcommits |
| 583 | |
| 584 | # push only the first 2 branches |
| 585 | git push origin main branch-to-delete |
| 586 | for ((a=0; a < 3 ; a++)) |
| 587 | do |
| 588 | assert_server_object "$reponame" "${oid[$a]}" |
| 589 | done |
| 590 | # confirm we haven't pushed the last one yet |
| 591 | refute_server_object "$reponame" "${oid[3]}" |
| 592 | # copy the cached remote ref for the branch we're going to delete remotely |
| 593 | cp .git/refs/remotes/origin/branch-to-delete branch-to-delete.ref |
| 594 | # now delete the branch on the server |
| 595 | git push origin --delete branch-to-delete |
| 596 | # remove the OID in it, as if GC'd |
| 597 | delete_server_object "$reponame" "${oid[2]}" |
| 598 | refute_server_object "$reponame" "${oid[2]}" |
| 599 | # Now put the cached remote ref back, as if someone else had deleted it but |
| 600 | # we hadn't done git fetch --prune yet |
| 601 | mv branch-to-delete.ref .git/refs/remotes/origin/branch-to-delete |
| 602 | # Confirm that local cache of remote branch is back |
| 603 | git branch -r 2>&1 | tee branch-r.log |
| 604 | grep "origin/branch-to-delete" branch-r.log |
| 605 | # Now push later branch which should now need to re-push previous commits LFS too |
| 606 | git push origin branch-to-push-after |
| 607 | # all objects should now be there even though cached remote branch claimed it already had file3.dat |
| 608 | for ((a=0; a < NUMFILES ; a++)) |
| 609 | do |
| 610 | assert_server_object "$reponame" "${oid[$a]}" |
| 611 | done |
| 612 | |
| 613 | ) |
| 614 | end_test |
| 615 | |
| 616 | begin_test "pre-push delete branch" |
| 617 | ( |
| 618 | set -e |
| 619 | |
| 620 | reponame="$(basename "$0" ".sh")-delete-branch" |
| 621 | setup_remote_repo "$reponame" |
| 622 | clone_repo "$reponame" "$reponame" |
| 623 | |
| 624 | |
| 625 | git lfs track "*.dat" 2>&1 | tee track.log |
| 626 | grep "Tracking \"\*.dat\"" track.log |
| 627 | |
| 628 | NUMFILES=4 |
| 629 | # generate content we'll use |
| 630 | for ((a=0; a < NUMFILES ; a++)) |
| 631 | do |
| 632 | content[$a]="filecontent$a" |
| 633 | oid[$a]=$(calc_oid "${content[$a]}") |
| 634 | done |
| 635 | |
| 636 | echo "[ |
| 637 | { |
| 638 | \"CommitDate\":\"$(get_date -2d)\", |
| 639 | \"Files\":[ |
| 640 | {\"Filename\":\"file1.dat\",\"Size\":${#content[0]}, \"Data\":\"${content[0]}\"}, |
| 641 | {\"Filename\":\"file2.dat\",\"Size\":${#content[1]}, \"Data\":\"${content[1]}\"}] |
| 642 | }, |
| 643 | { |
| 644 | \"NewBranch\":\"branch-to-delete\", |
| 645 | \"CommitDate\":\"$(get_date -1d)\", |
| 646 | \"Files\":[ |
| 647 | {\"Filename\":\"file3.dat\",\"Size\":${#content[2]}, \"Data\":\"${content[2]}\"}] |
| 648 | }, |
| 649 | { |
| 650 | \"ParentBranches\":[\"main\"], |
| 651 | \"CommitDate\":\"$(get_date -0d)\", |
| 652 | \"Files\":[ |
| 653 | {\"Filename\":\"file4.dat\",\"Size\":${#content[3]}, \"Data\":\"${content[3]}\"}] |
| 654 | } |
| 655 | ]" | lfstest-testutils addcommits |
| 656 | |
| 657 | # push all branches |
| 658 | git push origin main branch-to-delete |
| 659 | for ((a=0; a < NUMFILES ; a++)) |
| 660 | do |
| 661 | assert_server_object "$reponame" "${oid[$a]}" |
| 662 | done |
| 663 | |
| 664 | # deleting a branch with git push should not fail |
| 665 | # (requires correct special casing of "(delete) 0000000000.." in hook) |
| 666 | git push origin --delete branch-to-delete |
| 667 | ) |
| 668 | end_test |
| 669 | |
| 670 | begin_test "pre-push with our lock" |
| 671 | ( |
| 672 | set -e |
| 673 | |
| 674 | reponame="pre_push_owned_locks" |
| 675 | setup_remote_repo "$reponame" |
| 676 | clone_repo "$reponame" "$reponame" |
| 677 | |
| 678 | git lfs track "*.dat" |
| 679 | git add .gitattributes |
| 680 | git commit -m "initial commit" |
| 681 | |
| 682 | contents="locked contents" |
| 683 | printf "%s" "$contents" > locked.dat |
| 684 | git add locked.dat |
| 685 | git commit -m "add locked.dat" |
| 686 | |
| 687 | git push origin main |
| 688 | |
| 689 | git lfs lock --json "locked.dat" | tee lock.log |
| 690 | |
| 691 | id=$(assert_lock lock.log locked.dat) |
| 692 | assert_server_lock $id |
| 693 | |
| 694 | printf "authorized changes" >> locked.dat |
| 695 | git add locked.dat |
| 696 | git commit -m "add unauthorized changes" |
| 697 | |
| 698 | GIT_CURL_VERBOSE=1 git push origin main 2>&1 | tee push.log |
| 699 | grep "Consider unlocking your own locked files" push.log |
| 700 | grep "* locked.dat" push.log |
| 701 | |
| 702 | assert_server_lock "$id" |
| 703 | ) |
| 704 | end_test |
| 705 | |
| 706 | begin_test "pre-push with their lock on lfs file" |
| 707 | ( |
| 708 | set -e |
| 709 | |
| 710 | reponame="pre_push_unowned_lock" |
| 711 | setup_remote_repo "$reponame" |
| 712 | clone_repo "$reponame" "$reponame" |
| 713 | |
| 714 | git lfs track "*.dat" |
| 715 | git add .gitattributes |
| 716 | git commit -m "initial commit" |
| 717 | |
| 718 | contents="locked contents" |
| 719 | |
| 720 | # any lock path with "theirs" is returned as "their" lock by /locks/verify |
| 721 | printf "%s" "$contents" > locked_theirs.dat |
| 722 | git add locked_theirs.dat |
| 723 | git commit -m "add locked_theirs.dat" |
| 724 | |
| 725 | git push origin main |
| 726 | |
| 727 | git lfs lock --json "locked_theirs.dat" | tee lock.log |
| 728 | id=$(assert_lock lock.log locked_theirs.dat) |
| 729 | assert_server_lock $id |
| 730 | |
| 731 | pushd "$TRASHDIR" >/dev/null |
| 732 | clone_repo "$reponame" "$reponame-assert" |
| 733 | git config lfs.locksverify true |
| 734 | |
| 735 | printf "unauthorized changes" >> locked_theirs.dat |
| 736 | git add locked_theirs.dat |
| 737 | # --no-verify is used to avoid the pre-commit hook which is not under test |
| 738 | git commit --no-verify -m "add unauthorized changes" |
| 739 | |
| 740 | git push origin main 2>&1 | tee push.log |
| 741 | res="${PIPESTATUS[0]}" |
| 742 | if [ "0" -eq "$res" ]; then |
| 743 | echo "push should fail" |
| 744 | exit 1 |
| 745 | fi |
| 746 | |
| 747 | grep "Unable to push locked files" push.log |
| 748 | grep "* locked_theirs.dat - Git LFS Tests" push.log |
| 749 | |
| 750 | grep "Cannot update locked files." push.log |
| 751 | refute_server_object "$reponame" "$(calc_oid_file locked_theirs.dat)" |
| 752 | popd >/dev/null |
| 753 | ) |
| 754 | end_test |
| 755 | |
| 756 | begin_test "pre-push with their lock on non-lfs lockable file" |
| 757 | ( |
| 758 | set -e |
| 759 | |
| 760 | reponame="pre_push_unowned_lock_not_lfs" |
| 761 | setup_remote_repo "$reponame" |
| 762 | clone_repo "$reponame" "$reponame" |
| 763 | |
| 764 | echo "*.dat lockable" > .gitattributes |
| 765 | git add .gitattributes |
| 766 | git commit -m "initial commit" |
| 767 | |
| 768 | # any lock path with "theirs" is returned as "their" lock by /locks/verify |
| 769 | echo "hi" > readme.txt |
| 770 | echo "tiny" > tiny_locked_theirs.dat |
| 771 | git help > large_locked_theirs.dat |
| 772 | git add readme.txt tiny_locked_theirs.dat large_locked_theirs.dat |
| 773 | git commit -m "add initial files" |
| 774 | |
| 775 | git push origin main |
| 776 | |
| 777 | git lfs lock --json "tiny_locked_theirs.dat" | tee lock.log |
| 778 | id=$(assert_lock lock.log tiny_locked_theirs.dat) |
| 779 | assert_server_lock $id |
| 780 | |
| 781 | git lfs lock --json "large_locked_theirs.dat" | tee lock.log |
| 782 | id=$(assert_lock lock.log large_locked_theirs.dat) |
| 783 | assert_server_lock $id |
| 784 | |
| 785 | pushd "$TRASHDIR" >/dev/null |
| 786 | clone_repo "$reponame" "$reponame-assert" |
| 787 | git config lfs.locksverify true |
| 788 | |
| 789 | git lfs update # manually add pre-push hook, since lfs clean hook is not used |
| 790 | echo "other changes" >> readme.txt |
| 791 | echo "unauthorized changes" >> large_locked_theirs.dat |
| 792 | echo "unauthorized changes" >> tiny_locked_theirs.dat |
| 793 | # --no-verify is used to avoid the pre-commit hook which is not under test |
| 794 | git commit --no-verify -am "add unauthorized changes" |
| 795 | |
| 796 | git push origin main 2>&1 | tee push.log |
| 797 | res="${PIPESTATUS[0]}" |
| 798 | if [ "0" -eq "$res" ]; then |
| 799 | echo "push should fail" |
| 800 | exit 1 |
| 801 | fi |
| 802 | |
| 803 | grep "Unable to push locked files" push.log |
| 804 | grep "* large_locked_theirs.dat - Git LFS Tests" push.log |
| 805 | grep "* tiny_locked_theirs.dat - Git LFS Tests" push.log |
| 806 | grep "Cannot update locked files." push.log |
| 807 | |
| 808 | refute_server_object "$reponame" "$(calc_oid_file large_locked_theirs.dat)" |
| 809 | refute_server_object "$reponame" "$(calc_oid_file tiny_locked_theirs.dat)" |
| 810 | popd >/dev/null |
| 811 | ) |
| 812 | end_test |
| 813 | |
| 814 | begin_test "pre-push locks verify 5xx with verification enabled" |
| 815 | ( |
| 816 | set -e |
| 817 | |
| 818 | reponame="lock-enabled-verify-5xx" |
| 819 | setup_remote_repo "$reponame" |
| 820 | clone_repo "$reponame" "$reponame" |
| 821 | |
| 822 | endpoint="$(repo_endpoint $GITSERVER $reponame)" |
| 823 | |
| 824 | contents="example" |
| 825 | contents_oid="$(calc_oid "$contents")" |
| 826 | printf "%s" "$contents" > a.dat |
| 827 | git lfs track "*.dat" |
| 828 | git add .gitattributes a.dat |
| 829 | git commit --message "initial commit" |
| 830 | |
| 831 | git config "lfs.$endpoint.locksverify" true |
| 832 | |
| 833 | git push origin main 2>&1 | tee push.log |
| 834 | grep "\"origin\" does not support the Git LFS locking API" push.log |
| 835 | grep "git config lfs.$endpoint.locksverify false" push.log |
| 836 | |
| 837 | refute_server_object "$reponame" "$contents_oid" |
| 838 | ) |
| 839 | end_test |
| 840 | |
| 841 | begin_test "pre-push disable locks verify on exact url" |
| 842 | ( |
| 843 | set -e |
| 844 | |
| 845 | reponame="lock-disabled-verify-5xx" |
| 846 | setup_remote_repo "$reponame" |
| 847 | clone_repo "$reponame" "$reponame" |
| 848 | |
| 849 | endpoint="$(repo_endpoint $GITSERVER $reponame)" |
| 850 | |
| 851 | contents="example" |
| 852 | contents_oid="$(calc_oid "$contents")" |
| 853 | printf "%s" "$contents" > a.dat |
| 854 | git lfs track "*.dat" |
| 855 | git add .gitattributes a.dat |
| 856 | git commit --message "initial commit" |
| 857 | |
| 858 | git config "lfs.$endpoint.locksverify" false |
| 859 | |
| 860 | git push origin main 2>&1 | tee push.log |
| 861 | [ "0" -eq "$(grep -c "\"origin\" does not support the Git LFS locking API" push.log)" ] |
| 862 | |
| 863 | assert_server_object "$reponame" "$contents_oid" |
| 864 | ) |
| 865 | end_test |
| 866 | |
| 867 | begin_test "pre-push disable locks verify on partial url" |
| 868 | ( |
| 869 | set -e |
| 870 | |
| 871 | reponame="lock-disabled-verify-5xx-partial" |
| 872 | setup_remote_repo "$reponame" |
| 873 | clone_repo "$reponame" "$reponame" |
| 874 | |
| 875 | endpoint="$server/$repo" |
| 876 | |
| 877 | contents="example" |
| 878 | contents_oid="$(calc_oid "$contents")" |
| 879 | printf "%s" "$contents" > a.dat |
| 880 | git lfs track "*.dat" |
| 881 | git add .gitattributes a.dat |
| 882 | git commit --message "initial commit" |
| 883 | |
| 884 | git config "lfs.$endpoint.locksverify" false |
| 885 | |
| 886 | git push origin main 2>&1 | tee push.log |
| 887 | [ "0" -eq "$(grep -c "\"origin\" does not support the Git LFS locking API" push.log)" ] |
| 888 | |
| 889 | assert_server_object "$reponame" "$contents_oid" |
| 890 | ) |
| 891 | end_test |
| 892 | |
| 893 | begin_test "pre-push locks verify 403 with good ref" |
| 894 | ( |
| 895 | set -e |
| 896 | |
| 897 | reponame="lock-verify-main-branch-required" |
| 898 | setup_remote_repo "$reponame" |
| 899 | clone_repo "$reponame" "$reponame" |
| 900 | |
| 901 | contents="example" |
| 902 | contents_oid="$(calc_oid "$contents")" |
| 903 | printf "%s" "$contents" > a.dat |
| 904 | git lfs track "*.dat" |
| 905 | git add .gitattributes a.dat |
| 906 | git commit --message "initial commit" |
| 907 | |
| 908 | git config "lfs.$GITSERVER/$reponame.git.locksverify" true |
| 909 | git push origin main 2>&1 | tee push.log |
| 910 | |
| 911 | assert_server_object "$reponame" "$contents_oid" "refs/heads/main" |
| 912 | ) |
| 913 | end_test |
| 914 | |
| 915 | begin_test "pre-push locks verify 403 with good tracked ref" |
| 916 | ( |
| 917 | set -e |
| 918 | |
| 919 | reponame="lock-verify-tracked-branch-required" |
| 920 | setup_remote_repo "$reponame" |
| 921 | clone_repo "$reponame" "$reponame" |
| 922 | |
| 923 | contents="example" |
| 924 | contents_oid="$(calc_oid "$contents")" |
| 925 | printf "%s" "$contents" > a.dat |
| 926 | git lfs track "*.dat" |
| 927 | git add .gitattributes a.dat |
| 928 | git commit --message "initial commit" |
| 929 | |
| 930 | git config push.default upstream |
| 931 | git config branch.main.merge refs/heads/tracked |
| 932 | git config branch.main.remote origin |
| 933 | git config "lfs.$GITSERVER/$reponame.git.locksverify" true |
| 934 | git push 2>&1 | tee push.log |
| 935 | |
| 936 | assert_server_object "$reponame" "$contents_oid" "refs/heads/tracked" |
| 937 | ) |
| 938 | end_test |
| 939 | |
| 940 | begin_test "pre-push locks verify 403 with explicit ref" |
| 941 | ( |
| 942 | set -e |
| 943 | |
| 944 | reponame="lock-verify-explicit-branch-required" |
| 945 | setup_remote_repo "$reponame" |
| 946 | clone_repo "$reponame" "$reponame" |
| 947 | |
| 948 | contents="example" |
| 949 | contents_oid="$(calc_oid "$contents")" |
| 950 | printf "%s" "$contents" > a.dat |
| 951 | git lfs track "*.dat" |
| 952 | git add .gitattributes a.dat |
| 953 | git commit --message "initial commit" |
| 954 | |
| 955 | git config "lfs.$GITSERVER/$reponame.git.locksverify" true |
| 956 | git push origin main:explicit 2>&1 | tee push.log |
| 957 | |
| 958 | assert_server_object "$reponame" "$contents_oid" "refs/heads/explicit" |
| 959 | ) |
| 960 | end_test |
| 961 | |
| 962 | begin_test "pre-push locks verify 403 with bad ref" |
| 963 | ( |
| 964 | set -e |
| 965 | |
| 966 | reponame="lock-verify-other-branch-required" |
| 967 | setup_remote_repo "$reponame" |
| 968 | clone_repo "$reponame" "$reponame" |
| 969 | |
| 970 | contents="example" |
| 971 | contents_oid="$(calc_oid "$contents")" |
| 972 | printf "%s" "$contents" > a.dat |
| 973 | git lfs track "*.dat" |
| 974 | git add .gitattributes a.dat |
| 975 | git commit --message "initial commit" |
| 976 | |
| 977 | git config "lfs.$GITSERVER/$reponame.git.locksverify" true |
| 978 | git push origin main 2>&1 | tee push.log |
| 979 | grep "failed to push some refs" push.log |
| 980 | refute_server_object "$reponame" "$contents_oid" "refs/heads/other" |
| 981 | ) |
| 982 | end_test |
| 983 | |
| 984 | begin_test "pre-push locks verify 5xx with verification unset" |
| 985 | ( |
| 986 | set -e |
| 987 | |
| 988 | reponame="lock-unset-verify-5xx" |
| 989 | setup_remote_repo "$reponame" |
| 990 | clone_repo "$reponame" "$reponame" |
| 991 | |
| 992 | endpoint="$(repo_endpoint $GITSERVER $reponame)" |
| 993 | |
| 994 | contents="example" |
| 995 | contents_oid="$(calc_oid "$contents")" |
| 996 | printf "%s" "$contents" > a.dat |
| 997 | git lfs track "*.dat" |
| 998 | git add .gitattributes a.dat |
| 999 | git commit --message "initial commit" |
| 1000 | |
| 1001 | [ -z "$(git config "lfs.$endpoint.locksverify")" ] |
| 1002 | |
| 1003 | git push origin main 2>&1 | tee push.log |
| 1004 | grep "\"origin\" does not support the Git LFS locking API" push.log |
| 1005 | |
| 1006 | assert_server_object "$reponame" "$contents_oid" |
| 1007 | ) |
| 1008 | end_test |
| 1009 | |
| 1010 | begin_test "pre-push locks verify 501 with verification enabled" |
| 1011 | ( |
| 1012 | set -e |
| 1013 | |
| 1014 | reponame="lock-enabled-verify-501" |
| 1015 | setup_remote_repo "$reponame" |
| 1016 | clone_repo "$reponame" "$reponame" |
| 1017 | |
| 1018 | endpoint="$(repo_endpoint $GITSERVER $reponame)" |
| 1019 | |
| 1020 | contents="example" |
| 1021 | contents_oid="$(calc_oid "$contents")" |
| 1022 | printf "%s" "$contents" > a.dat |
| 1023 | git lfs track "*.dat" |
| 1024 | git add .gitattributes a.dat |
| 1025 | git commit --message "initial commit" |
| 1026 | |
| 1027 | git config "lfs.$endpoint.locksverify" true |
| 1028 | |
| 1029 | git push origin main 2>&1 | tee push.log |
| 1030 | |
| 1031 | assert_server_object "$reponame" "$contents_oid" |
| 1032 | [ "false" = "$(git config "lfs.$endpoint.locksverify")" ] |
| 1033 | ) |
| 1034 | end_test |
| 1035 | |
| 1036 | |
| 1037 | begin_test "pre-push locks verify 501 with verification disabled" |
| 1038 | ( |
| 1039 | set -e |
| 1040 | |
| 1041 | reponame="lock-disabled-verify-501" |
| 1042 | setup_remote_repo "$reponame" |
| 1043 | clone_repo "$reponame" "$reponame" |
| 1044 | |
| 1045 | endpoint="$(repo_endpoint $GITSERVER $reponame)" |
| 1046 | |
| 1047 | contents="example" |
| 1048 | contents_oid="$(calc_oid "$contents")" |
| 1049 | printf "%s" "$contents" > a.dat |
| 1050 | git lfs track "*.dat" |
| 1051 | git add .gitattributes a.dat |
| 1052 | git commit --message "initial commit" |
| 1053 | |
| 1054 | git config "lfs.$endpoint.locksverify" false |
| 1055 | |
| 1056 | git push origin main 2>&1 | tee push.log |
| 1057 | |
| 1058 | assert_server_object "$reponame" "$contents_oid" |
| 1059 | [ "false" = "$(git config "lfs.$endpoint.locksverify")" ] |
| 1060 | ) |
| 1061 | end_test |
| 1062 | |
| 1063 | begin_test "pre-push locks verify 501 with verification unset" |
| 1064 | ( |
| 1065 | set -e |
| 1066 | |
| 1067 | reponame="lock-unset-verify-501" |
| 1068 | setup_remote_repo "$reponame" |
| 1069 | clone_repo "$reponame" "$reponame" |
| 1070 | |
| 1071 | endpoint="$(repo_endpoint $GITSERVER $reponame)" |
| 1072 | |
| 1073 | contents="example" |
| 1074 | contents_oid="$(calc_oid "$contents")" |
| 1075 | printf "%s" "$contents" > a.dat |
| 1076 | git lfs track "*.dat" |
| 1077 | git add .gitattributes a.dat |
| 1078 | git commit --message "initial commit" |
| 1079 | |
| 1080 | [ -z "$(git config "lfs.$endpoint.locksverify")" ] |
| 1081 | |
| 1082 | git push origin main 2>&1 | tee push.log |
| 1083 | |
| 1084 | assert_server_object "$reponame" "$contents_oid" |
| 1085 | [ "false" = "$(git config "lfs.$endpoint.locksverify")" ] |
| 1086 | ) |
| 1087 | end_test |
| 1088 | |
| 1089 | begin_test "pre-push locks verify 200" |
| 1090 | ( |
| 1091 | set -e |
| 1092 | |
| 1093 | reponame="lock-verify-200" |
| 1094 | setup_remote_repo "$reponame" |
| 1095 | clone_repo "$reponame" "$reponame" |
| 1096 | |
| 1097 | endpoint="$(repo_endpoint $GITSERVER $reponame)" |
| 1098 | [ -z "$(git config "lfs.$endpoint.locksverify")" ] |
| 1099 | |
| 1100 | contents="example" |
| 1101 | contents_oid="$(calc_oid "$contents")" |
| 1102 | printf "%s" "$contents" > a.dat |
| 1103 | git lfs track "*.dat" |
| 1104 | git add .gitattributes a.dat |
| 1105 | git commit --message "initial commit" |
| 1106 | |
| 1107 | git push origin main 2>&1 | tee push.log |
| 1108 | |
| 1109 | grep "Locking support detected on remote \"origin\"." push.log |
| 1110 | grep "git config lfs.$endpoint.locksverify true" push.log |
| 1111 | assert_server_object "$reponame" "$contents_oid" |
| 1112 | ) |
| 1113 | end_test |
| 1114 | |
| 1115 | begin_test "pre-push locks verify 403 with verification enabled" |
| 1116 | ( |
| 1117 | set -e |
| 1118 | |
| 1119 | reponame="lock-enabled-verify-403" |
| 1120 | setup_remote_repo "$reponame" |
| 1121 | clone_repo "$reponame" "$reponame" |
| 1122 | |
| 1123 | endpoint="$(repo_endpoint $GITSERVER $reponame)" |
| 1124 | |
| 1125 | contents="example" |
| 1126 | contents_oid="$(calc_oid "$contents")" |
| 1127 | printf "%s" "$contents" > a.dat |
| 1128 | git lfs track "*.dat" |
| 1129 | git add .gitattributes a.dat |
| 1130 | git commit --message "initial commit" |
| 1131 | |
| 1132 | git config "lfs.$endpoint.locksverify" true |
| 1133 | |
| 1134 | git push origin main 2>&1 | tee push.log |
| 1135 | grep "error: Authentication error" push.log |
| 1136 | |
| 1137 | refute_server_object "$reponame" "$contents_oid" |
| 1138 | [ "true" = "$(git config "lfs.$endpoint.locksverify")" ] |
| 1139 | ) |
| 1140 | end_test |
| 1141 | |
| 1142 | begin_test "pre-push locks verify 403 with verification disabled" |
| 1143 | ( |
| 1144 | set -e |
| 1145 | |
| 1146 | reponame="lock-disabled-verify-403" |
| 1147 | setup_remote_repo "$reponame" |
| 1148 | clone_repo "$reponame" "$reponame" |
| 1149 | |
| 1150 | endpoint="$(repo_endpoint $GITSERVER $reponame)" |
| 1151 | |
| 1152 | contents="example" |
| 1153 | contents_oid="$(calc_oid "$contents")" |
| 1154 | printf "%s" "$contents" > a.dat |
| 1155 | git lfs track "*.dat" |
| 1156 | git add .gitattributes a.dat |
| 1157 | git commit --message "initial commit" |
| 1158 | |
| 1159 | git config "lfs.$endpoint.locksverify" false |
| 1160 | |
| 1161 | git push origin main 2>&1 | tee push.log |
| 1162 | |
| 1163 | assert_server_object "$reponame" "$contents_oid" |
| 1164 | [ "false" = "$(git config "lfs.$endpoint.locksverify")" ] |
| 1165 | ) |
| 1166 | end_test |
| 1167 | |
| 1168 | begin_test "pre-push locks verify 403 with verification unset" |
| 1169 | ( |
| 1170 | set -e |
| 1171 | |
| 1172 | reponame="lock-unset-verify-403" |
| 1173 | setup_remote_repo "$reponame" |
| 1174 | clone_repo "$reponame" "$reponame" |
| 1175 | |
| 1176 | endpoint="$(repo_endpoint $GITSERVER $reponame)" |
| 1177 | |
| 1178 | contents="example" |
| 1179 | contents_oid="$(calc_oid "$contents")" |
| 1180 | printf "%s" "$contents" > a.dat |
| 1181 | git lfs track "*.dat" |
| 1182 | git add .gitattributes a.dat |
| 1183 | git commit --message "initial commit" |
| 1184 | |
| 1185 | [ -z "$(git config "lfs.$endpoint.locksverify")" ] |
| 1186 | |
| 1187 | git push origin main 2>&1 | tee push.log |
| 1188 | grep "warning: Authentication error" push.log |
| 1189 | |
| 1190 | assert_server_object "$reponame" "$contents_oid" |
| 1191 | [ -z "$(git config "lfs.$endpoint.locksverify")" ] |
| 1192 | ) |
| 1193 | end_test |
| 1194 | |
| 1195 | begin_test "pre-push with pushDefault and explicit remote" |
| 1196 | ( |
| 1197 | set -e |
| 1198 | reponame="pre-push-pushdefault-explicit" |
| 1199 | setup_remote_repo "$reponame" |
| 1200 | clone_repo "$reponame" "$reponame" |
| 1201 | |
| 1202 | git remote add wrong "$(repo_endpoint "$GITSERVER" "wrong-url")" |
| 1203 | |
| 1204 | git config "lfs.$(repo_endpoint "$GITSERVER" "$reponame").locksverify" false |
| 1205 | git config remote.pushDefault wrong |
| 1206 | git lfs track "*.dat" |
| 1207 | echo "hi" > a.dat |
| 1208 | git add .gitattributes a.dat |
| 1209 | git commit -m "add a.dat" |
| 1210 | |
| 1211 | refute_server_object "$reponame" 98ea6e4f216f2fb4b69fff9b3a44842c38686ca685f3f55dc48c5d3fb1107be4 "refs/heads/main" |
| 1212 | |
| 1213 | GIT_TRACE=1 GIT_TRANSFER_TRACE=1 git push origin main 2>&1 | tee push.log |
| 1214 | |
| 1215 | assert_server_object "$reponame" 98ea6e4f216f2fb4b69fff9b3a44842c38686ca685f3f55dc48c5d3fb1107be4 "refs/heads/main" |
| 1216 | grep wrong-url push.log && exit 1 |
| 1217 | true |
| 1218 | ) |
| 1219 | end_test |
| 1220 | |
| 1221 | begin_test "pre-push uses optimization if remote URL matches" |
| 1222 | ( |
| 1223 | set -e |
| 1224 | reponame="pre-push-remote-url-optimization" |
| 1225 | setup_remote_repo "$reponame" |
| 1226 | clone_repo "$reponame" "$reponame" |
| 1227 | |
| 1228 | endpoint=$(git config remote.origin.url) |
| 1229 | git config "lfs.$endpoint.locksverify" false |
| 1230 | git lfs track "*.dat" |
| 1231 | echo "hi" > a.dat |
| 1232 | contents_oid="$(calc_oid_file "a.dat")" |
| 1233 | git add .gitattributes a.dat |
| 1234 | git commit -m "add a.dat" |
| 1235 | |
| 1236 | refute_server_object "$reponame" $contents_oid "refs/heads/main" |
| 1237 | |
| 1238 | GIT_TRACE=1 GIT_TRANSFER_TRACE=1 git push "$endpoint" main 2>&1 | tee push.log |
| 1239 | grep 'rev-list.*--not --remotes=origin' push.log |
| 1240 | ) |
| 1241 | end_test |
| 1242 | |
| 1243 | begin_test "pre-push does not traverse Git objects server has" |
| 1244 | ( |
| 1245 | set -e |
| 1246 | reponame="pre-push-traverse-server-objects" |
| 1247 | setup_remote_repo "$reponame" |
| 1248 | clone_repo "$reponame" "$reponame" |
| 1249 | |
| 1250 | endpoint=$(git config remote.origin.url) |
| 1251 | git config "lfs.$endpoint.locksverify" false |
| 1252 | git lfs track "*.dat" |
| 1253 | echo "hi" > a.dat |
| 1254 | contents_oid="$(calc_oid_file "a.dat")" |
| 1255 | git add .gitattributes a.dat |
| 1256 | git commit -m "add a.dat" |
| 1257 | |
| 1258 | refute_server_object "$reponame" $contents_oid "refs/heads/main" |
| 1259 | |
| 1260 | # We use a different URL instead of a named remote or the remote URL so that |
| 1261 | # we can't make use of the optimization that ignores objects we already have |
| 1262 | # in remote tracking branches. |
| 1263 | GIT_TRACE=1 GIT_TRANSFER_TRACE=1 git push "$endpoint.git" main 2>&1 | tee push.log |
| 1264 | |
| 1265 | assert_server_object "$reponame" $contents_oid "refs/heads/main" |
| 1266 | |
| 1267 | echo "hello" > b.dat |
| 1268 | contents2_oid="$(calc_oid_file "b.dat")" |
| 1269 | git add .gitattributes b.dat |
| 1270 | git commit -m "add b.dat" |
| 1271 | |
| 1272 | refute_server_object "$reponame" $contents2_oid "refs/heads/main" |
| 1273 | |
| 1274 | GIT_TRACE=1 GIT_TRANSFER_TRACE=1 git push "$endpoint.git" main 2>&1 | tee push.log |
| 1275 | |
| 1276 | assert_server_object "$reponame" $contents2_oid "refs/heads/main" |
| 1277 | |
| 1278 | # Verify that we haven't tried to push or query for the object we already |
| 1279 | # pushed before; i.e., we didn't see it because we ignored its Git object |
| 1280 | # during traversal. |
| 1281 | grep $contents_oid push.log && exit 1 |
| 1282 | true |
| 1283 | ) |
| 1284 | end_test |
| 1285 | |
| 1286 | begin_test "pre-push with force-pushed ref" |
| 1287 | ( |
| 1288 | set -e |
| 1289 | reponame="pre-push-force-pushed-ref" |
| 1290 | setup_remote_repo "$reponame" |
| 1291 | clone_repo "$reponame" "$reponame" |
| 1292 | |
| 1293 | git config "lfs.$(repo_endpoint "$GITSERVER" "$reponame").locksverify" false |
| 1294 | git lfs track "*.dat" |
| 1295 | echo "hi" > a.dat |
| 1296 | git add .gitattributes a.dat |
| 1297 | git commit -m "add a.dat" |
| 1298 | git tag -a -m tagname tagname |
| 1299 | |
| 1300 | refute_server_object "$reponame" 98ea6e4f216f2fb4b69fff9b3a44842c38686ca685f3f55dc48c5d3fb1107be4 "refs/heads/main" |
| 1301 | |
| 1302 | git push origin main tagname |
| 1303 | |
| 1304 | assert_server_object "$reponame" 98ea6e4f216f2fb4b69fff9b3a44842c38686ca685f3f55dc48c5d3fb1107be4 "refs/heads/main" |
| 1305 | |
| 1306 | # We pick a different message so that we get different object IDs even if both |
| 1307 | # commands run in the same second. |
| 1308 | git tag -f -a -m tagname2 tagname |
| 1309 | # Prune the old tag object. |
| 1310 | git reflog expire --all --expire=now |
| 1311 | git gc --prune=now |
| 1312 | # Make sure we deal with us missing the object for the old value of the tag ref. |
| 1313 | git push origin +tagname |
| 1314 | ) |
| 1315 | end_test |
| 1316 | |
| 1317 | begin_test "pre-push with local path" |
| 1318 | ( |
| 1319 | set -e |
| 1320 | reponame="pre-push-local-path" |
| 1321 | setup_remote_repo "$reponame" |
| 1322 | clone_repo "$reponame" "$reponame-2" |
| 1323 | cd .. |
| 1324 | clone_repo "$reponame" "$reponame" |
| 1325 | |
| 1326 | git lfs track "*.dat" |
| 1327 | echo "hi" > a.dat |
| 1328 | git add .gitattributes a.dat |
| 1329 | git commit -m "add a.dat" |
| 1330 | |
| 1331 | # Push to the other repo. |
| 1332 | git push "../$reponame-2" main:foo |
| 1333 | |
| 1334 | # Push to . to make sure that works. |
| 1335 | git push "." main:foo |
| 1336 | |
| 1337 | git lfs fsck |
| 1338 | cd "../$reponame-2" |
| 1339 | git checkout foo |
| 1340 | git lfs fsck |
| 1341 | ) |
| 1342 | end_test |