| 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | . "$(dirname "$0")/testlib.sh" |
| 4 | |
| 5 | setup_repo () { |
| 6 | setup_remote_repo_with_file "$1" "$2" |
| 7 | |
| 8 | git lfs track --lockable "*.dat" |
| 9 | git add -u |
| 10 | git commit -m 'Mark files lockable' |
| 11 | } |
| 12 | |
| 13 | begin_test "unlocking a lock by path without a ref required" |
| 14 | ( |
| 15 | set -e |
| 16 | |
| 17 | reponame="unlock-by-path-main-branch-not-required" |
| 18 | setup_repo "$reponame" "c.dat" |
| 19 | |
| 20 | git lfs lock --json "c.dat" | tee lock.log |
| 21 | |
| 22 | id=$(assert_lock lock.log c.dat) |
| 23 | assert_server_lock "$reponame" "$id" "refs/heads/main" |
| 24 | |
| 25 | git lfs unlock "c.dat" |
| 26 | refute_server_lock "$reponame" "$id" "refs/heads/main" |
| 27 | ) |
| 28 | end_test |
| 29 | |
| 30 | begin_test "unlocking a lock by path with good ref" |
| 31 | ( |
| 32 | set -e |
| 33 | |
| 34 | reponame="unlock-by-path-main-branch-required" |
| 35 | setup_repo "$reponame" "c.dat" |
| 36 | |
| 37 | git lfs lock --json "c.dat" | tee lock.log |
| 38 | |
| 39 | id=$(assert_lock lock.log c.dat) |
| 40 | assert_server_lock "$reponame" "$id" "refs/heads/main" |
| 41 | |
| 42 | git lfs unlock "c.dat" |
| 43 | refute_server_lock "$reponame" "$id" "refs/heads/main" |
| 44 | ) |
| 45 | end_test |
| 46 | |
| 47 | begin_test "unlocking a lock by id with good ref" |
| 48 | ( |
| 49 | set -e |
| 50 | |
| 51 | reponame="unlock-by-id-main-branch-required" |
| 52 | setup_repo "$reponame" "c.dat" |
| 53 | |
| 54 | git lfs lock --json "c.dat" | tee lock.log |
| 55 | |
| 56 | id=$(assert_lock lock.log c.dat) |
| 57 | assert_server_lock "$reponame" "$id" "refs/heads/main" |
| 58 | |
| 59 | git lfs unlock --id="$id" |
| 60 | refute_server_lock "$reponame" "$id" "refs/heads/main" |
| 61 | ) |
| 62 | end_test |
| 63 | |
| 64 | begin_test "unlocking a lock by path with tracked ref" |
| 65 | ( |
| 66 | set -e |
| 67 | |
| 68 | reponame="unlock-by-path-tracked-branch-required" |
| 69 | setup_remote_repo "$reponame" |
| 70 | clone_repo "$reponame" "$reponame" |
| 71 | |
| 72 | git lfs track "*.dat" |
| 73 | echo "c" > c.dat |
| 74 | git add .gitattributes c.dat |
| 75 | git commit -m "add c.dat" |
| 76 | |
| 77 | git config push.default upstream |
| 78 | git config branch.main.merge refs/heads/tracked |
| 79 | git config branch.main.remote origin |
| 80 | git push origin main |
| 81 | |
| 82 | git lfs lock --json "c.dat" | tee lock.log |
| 83 | |
| 84 | id=$(assert_lock lock.log c.dat) |
| 85 | assert_server_lock "$reponame" "$id" "refs/heads/tracked" |
| 86 | |
| 87 | git lfs unlock "c.dat" |
| 88 | refute_server_lock "$reponame" "$id" "refs/heads/tracked" |
| 89 | ) |
| 90 | end_test |
| 91 | |
| 92 | begin_test "unlocking a lock by id with tracked ref" |
| 93 | ( |
| 94 | set -e |
| 95 | |
| 96 | reponame="unlock-by-id-tracked-branch-required" |
| 97 | setup_remote_repo "$reponame" |
| 98 | clone_repo "$reponame" "$reponame" |
| 99 | |
| 100 | git lfs track "*.dat" |
| 101 | echo "c" > c.dat |
| 102 | git add .gitattributes c.dat |
| 103 | git commit -m "add c.dat" |
| 104 | |
| 105 | git config push.default upstream |
| 106 | git config branch.main.merge refs/heads/tracked |
| 107 | git config branch.main.remote origin |
| 108 | git push origin main |
| 109 | |
| 110 | git lfs lock --json "c.dat" | tee lock.log |
| 111 | |
| 112 | id=$(assert_lock lock.log c.dat) |
| 113 | assert_server_lock "$reponame" "$id" "refs/heads/tracked" |
| 114 | |
| 115 | git lfs unlock --id="$id" |
| 116 | refute_server_lock "$reponame" "$id" "refs/heads/tracked" |
| 117 | ) |
| 118 | end_test |
| 119 | |
| 120 | begin_test "unlock by id with good ref (--remote overrides push default)" |
| 121 | ( |
| 122 | set -e |
| 123 | |
| 124 | reponame="unlock-by-id-remote" |
| 125 | setup_remote_repo_with_file "$reponame" "a.dat" |
| 126 | clone_repo "$reponame" "$reponame" |
| 127 | |
| 128 | git lfs lock --json "a.dat" | tee lock.log |
| 129 | |
| 130 | id=$(assert_lock lock.log "a.dat") |
| 131 | assert_server_lock "$reponame" "$id" "refs/heads/main" |
| 132 | |
| 133 | # Check invalid "remote.pushDefault" configuration causes error. |
| 134 | git remote add bad-remote "invalid-url" |
| 135 | git config remote.pushDefault bad-remote |
| 136 | |
| 137 | git lfs unlock --id="$id" 2>&1 | tee unlock.log |
| 138 | if [ "0" -eq "${PIPESTATUS[0]}" ]; then |
| 139 | echo >&2 "fatal: expected 'git lfs unlock' to fail ..." |
| 140 | exit 1 |
| 141 | fi |
| 142 | |
| 143 | # Check --remote option overrides "remote.pushDefault" configuration. |
| 144 | git lfs unlock --remote origin --json --id="$id" | tee unlock.log |
| 145 | if [ "0" -ne "${PIPESTATUS[0]}" ]; then |
| 146 | echo >&2 "fatal: expected 'git lfs unlock' to succeed ..." |
| 147 | exit 1 |
| 148 | fi |
| 149 | |
| 150 | grep -F '[{"id":"'"$id"'","unlocked":true}]' unlock.log |
| 151 | refute_server_lock "$reponame" "$id" "refs/heads/main" |
| 152 | |
| 153 | # Remove "remote.pushDefault" configuration and lock again. |
| 154 | git config --unset remote.pushDefault |
| 155 | |
| 156 | git lfs lock --json "a.dat" | tee lock.log |
| 157 | |
| 158 | id=$(assert_lock lock.log "a.dat") |
| 159 | assert_server_lock "$reponame" "$id" "refs/heads/main" |
| 160 | |
| 161 | # Check invalid "branch.<name>.pushRemote" configuration causes error. |
| 162 | git config branch.main.pushRemote bad-remote |
| 163 | |
| 164 | git lfs unlock --id="$id" 2>&1 | tee unlock.log |
| 165 | if [ "0" -eq "${PIPESTATUS[0]}" ]; then |
| 166 | echo >&2 "fatal: expected 'git lfs unlock' to fail ..." |
| 167 | exit 1 |
| 168 | fi |
| 169 | |
| 170 | # Check --remote option overrides "branch.<name>.pushRemote" configuration. |
| 171 | git lfs unlock --remote origin --json --id="$id" | tee unlock.log |
| 172 | if [ "0" -ne "${PIPESTATUS[0]}" ]; then |
| 173 | echo >&2 "fatal: expected 'git lfs unlock' to succeed ..." |
| 174 | exit 1 |
| 175 | fi |
| 176 | |
| 177 | grep -F '[{"id":"'"$id"'","unlocked":true}]' unlock.log |
| 178 | refute_server_lock "$reponame" "$id" "refs/heads/main" |
| 179 | ) |
| 180 | end_test |
| 181 | |
| 182 | begin_test "unlock by path with good ref (--remote overrides push default)" |
| 183 | ( |
| 184 | set -e |
| 185 | |
| 186 | reponame="unlock-by-path-remote" |
| 187 | setup_remote_repo_with_file "$reponame" "a.dat" |
| 188 | clone_repo "$reponame" "$reponame" |
| 189 | |
| 190 | git lfs lock --json "a.dat" | tee lock.log |
| 191 | |
| 192 | id=$(assert_lock lock.log "a.dat") |
| 193 | assert_server_lock "$reponame" "$id" "refs/heads/main" |
| 194 | |
| 195 | # Check invalid "remote.pushDefault" configuration causes error. |
| 196 | git remote add bad-remote "invalid-url" |
| 197 | git config remote.pushDefault bad-remote |
| 198 | |
| 199 | git lfs unlock "a.dat" 2>&1 | tee unlock.log |
| 200 | if [ "0" -eq "${PIPESTATUS[0]}" ]; then |
| 201 | echo >&2 "fatal: expected 'git lfs unlock' to fail ..." |
| 202 | exit 1 |
| 203 | fi |
| 204 | |
| 205 | # Check --remote option overrides "remote.pushDefault" configuration. |
| 206 | git lfs unlock --remote origin --json "a.dat" | tee unlock.log |
| 207 | if [ "0" -ne "${PIPESTATUS[0]}" ]; then |
| 208 | echo >&2 "fatal: expected 'git lfs unlock' to succeed ..." |
| 209 | exit 1 |
| 210 | fi |
| 211 | |
| 212 | grep -F '[{"path":"a.dat","unlocked":true}]' unlock.log |
| 213 | refute_server_lock "$reponame" "$id" "refs/heads/main" |
| 214 | |
| 215 | # Remove "remote.pushDefault" configuration and lock again. |
| 216 | git config --unset remote.pushDefault |
| 217 | |
| 218 | git lfs lock --json "a.dat" | tee lock.log |
| 219 | |
| 220 | id=$(assert_lock lock.log "a.dat") |
| 221 | assert_server_lock "$reponame" "$id" "refs/heads/main" |
| 222 | |
| 223 | # Check invalid "branch.<name>.pushRemote" configuration causes error. |
| 224 | git config branch.main.pushRemote bad-remote |
| 225 | |
| 226 | git lfs unlock "a.dat" 2>&1 | tee unlock.log |
| 227 | if [ "0" -eq "${PIPESTATUS[0]}" ]; then |
| 228 | echo >&2 "fatal: expected 'git lfs unlock' to fail ..." |
| 229 | exit 1 |
| 230 | fi |
| 231 | |
| 232 | # Check --remote option overrides "branch.<name>.pushRemote" configuration. |
| 233 | git lfs unlock --remote origin --json "a.dat" | tee unlock.log |
| 234 | if [ "0" -ne "${PIPESTATUS[0]}" ]; then |
| 235 | echo >&2 "fatal: expected 'git lfs unlock' to succeed ..." |
| 236 | exit 1 |
| 237 | fi |
| 238 | |
| 239 | grep -F '[{"path":"a.dat","unlocked":true}]' unlock.log |
| 240 | refute_server_lock "$reponame" "$id" "refs/heads/main" |
| 241 | ) |
| 242 | end_test |
| 243 | |
| 244 | begin_test "unlocking a lock by path with bad ref without a ref required" |
| 245 | ( |
| 246 | set -e |
| 247 | |
| 248 | reponame="unlock-by-path-other-branch-not-required" |
| 249 | setup_remote_repo "$reponame" |
| 250 | clone_repo "$reponame" "$reponame" |
| 251 | |
| 252 | git lfs track "*.dat" |
| 253 | echo "c" > c.dat |
| 254 | git add .gitattributes c.dat |
| 255 | git commit -m "add c.dat" |
| 256 | git push origin main:other |
| 257 | |
| 258 | git checkout -b other |
| 259 | git lfs lock --json "c.dat" | tee lock.log |
| 260 | |
| 261 | id=$(assert_lock lock.log c.dat) |
| 262 | assert_server_lock "$reponame" "$id" "refs/heads/other" |
| 263 | |
| 264 | git checkout main |
| 265 | git lfs unlock "c.dat" |
| 266 | refute_server_lock "$reponame" "$id" "refs/heads/other" |
| 267 | ) |
| 268 | end_test |
| 269 | |
| 270 | begin_test "unlocking a lock by path with bad ref" |
| 271 | ( |
| 272 | set -e |
| 273 | |
| 274 | reponame="unlock-by-path-other-branch-required" |
| 275 | setup_remote_repo "$reponame" |
| 276 | clone_repo "$reponame" "$reponame" |
| 277 | |
| 278 | git lfs track "*.dat" |
| 279 | echo "c" > c.dat |
| 280 | git add .gitattributes c.dat |
| 281 | git commit -m "add c.dat" |
| 282 | git push origin main:other |
| 283 | |
| 284 | git checkout -b other |
| 285 | git lfs lock --json "c.dat" | tee lock.log |
| 286 | |
| 287 | id=$(assert_lock lock.log c.dat) |
| 288 | assert_server_lock "$reponame" "$id" "refs/heads/other" |
| 289 | |
| 290 | git checkout main |
| 291 | git lfs unlock "c.dat" 2>&1 | tee unlock.log |
| 292 | if [ "0" -eq "${PIPESTATUS[0]}" ]; then |
| 293 | echo >&2 "fatal: expected 'git lfs lock \'a.dat\'' to fail" |
| 294 | exit 1 |
| 295 | fi |
| 296 | |
| 297 | assert_server_lock "$reponame" "$id" "refs/heads/other" |
| 298 | grep 'Expected ref "refs/heads/other", got "refs/heads/main"' unlock.log |
| 299 | ) |
| 300 | end_test |
| 301 | |
| 302 | begin_test "unlocking a lock by id with bad ref" |
| 303 | ( |
| 304 | set -e |
| 305 | |
| 306 | reponame="unlock-by-id-other-branch-required" |
| 307 | setup_remote_repo "$reponame" |
| 308 | clone_repo "$reponame" "$reponame" |
| 309 | |
| 310 | git lfs track "*.dat" |
| 311 | echo "c" > c.dat |
| 312 | git add .gitattributes c.dat |
| 313 | git commit -m "add c.dat" |
| 314 | git push origin main:other |
| 315 | |
| 316 | git checkout -b other |
| 317 | git lfs lock --json "c.dat" | tee lock.log |
| 318 | |
| 319 | id=$(assert_lock lock.log c.dat) |
| 320 | assert_server_lock "$reponame" "$id" "refs/heads/other" |
| 321 | |
| 322 | git checkout main |
| 323 | git lfs unlock --id="$id" 2>&1 | tee unlock.log |
| 324 | if [ "0" -eq "${PIPESTATUS[0]}" ]; then |
| 325 | echo >&2 "fatal: expected 'git lfs lock \'a.dat\'' to fail" |
| 326 | exit 1 |
| 327 | fi |
| 328 | |
| 329 | assert_server_lock "$reponame" "$id" "refs/heads/other" |
| 330 | grep 'Expected ref "refs/heads/other", got "refs/heads/main"' unlock.log |
| 331 | ) |
| 332 | end_test |
| 333 | |
| 334 | begin_test "unlock multiple files" |
| 335 | ( |
| 336 | set -e |
| 337 | |
| 338 | reponame="unlock-multiple-files" |
| 339 | setup_remote_repo "$reponame" |
| 340 | clone_repo "$reponame" "$reponame" |
| 341 | |
| 342 | git lfs track "*.dat" |
| 343 | echo "a" > a.dat |
| 344 | echo "b" > b.dat |
| 345 | git add .gitattributes a.dat b.dat |
| 346 | git commit -m "add dat files" |
| 347 | git push origin main:other |
| 348 | |
| 349 | git lfs lock a.dat |
| 350 | git lfs lock b.dat |
| 351 | git lfs unlock *.dat >log 2>&1 |
| 352 | grep "Exactly one of --id or a set of paths must be provided" log && exit 1 |
| 353 | true |
| 354 | ) |
| 355 | end_test |
| 356 | |
| 357 | begin_test "unlock multiple files (JSON)" |
| 358 | ( |
| 359 | set -e |
| 360 | |
| 361 | reponame="unlock-multiple-files-json" |
| 362 | setup_remote_repo "$reponame" |
| 363 | clone_repo "$reponame" "$reponame" |
| 364 | |
| 365 | git lfs track "*.dat" |
| 366 | echo "a" > a.dat |
| 367 | echo "b" > b.dat |
| 368 | git add .gitattributes a.dat b.dat |
| 369 | git commit -m "add dat files" |
| 370 | git push origin main:other |
| 371 | |
| 372 | git lfs lock a.dat |
| 373 | git lfs lock b.dat |
| 374 | git lfs unlock --json *.dat | tee lock.json |
| 375 | grep -F '[{"path":"a.dat","unlocked":true},{"path":"b.dat","unlocked":true}]' lock.json |
| 376 | ) |
| 377 | end_test |
| 378 | |
| 379 | begin_test "unlocking a file makes it readonly" |
| 380 | ( |
| 381 | set -e |
| 382 | |
| 383 | reponame="unlock_set_readonly" |
| 384 | setup_repo "$reponame" "c.dat" |
| 385 | |
| 386 | git lfs lock --json "c.dat" |
| 387 | assert_file_writeable c.dat |
| 388 | |
| 389 | git lfs unlock "c.dat" |
| 390 | refute_file_writeable c.dat |
| 391 | ) |
| 392 | end_test |
| 393 | |
| 394 | begin_test "unlocking a file ignores readonly" |
| 395 | ( |
| 396 | set -e |
| 397 | |
| 398 | reponame="unlock_set_readonly_ignore" |
| 399 | setup_repo "$reponame" "c.dat" |
| 400 | |
| 401 | git lfs lock --json "c.dat" |
| 402 | assert_file_writeable c.dat |
| 403 | |
| 404 | git -c lfs.setlockablereadonly=false lfs unlock "c.dat" |
| 405 | assert_file_writeable c.dat |
| 406 | ) |
| 407 | end_test |
| 408 | |
| 409 | begin_test "unlocking lock removed file" |
| 410 | ( |
| 411 | set -e |
| 412 | |
| 413 | reponame="unlock-removed-file" |
| 414 | setup_repo "$reponame" "a.dat" |
| 415 | |
| 416 | git lfs lock --json "a.dat" | tee lock.log |
| 417 | id=$(assert_lock lock.log a.dat) |
| 418 | assert_server_lock "$reponame" "$id" |
| 419 | |
| 420 | git rm a.dat |
| 421 | git commit -m "a.dat" |
| 422 | rm *.log *.json # ensure clean git status |
| 423 | git status |
| 424 | |
| 425 | git lfs unlock --force "a.dat" 2>&1 | tee unlock.log |
| 426 | refute_server_lock "$reponame" "$id" |
| 427 | ) |
| 428 | end_test |
| 429 | |
| 430 | begin_test "unlocking nonexistent file" |
| 431 | ( |
| 432 | set -e |
| 433 | |
| 434 | reponame="unlock-nonexistent-file" |
| 435 | setup_repo "$reponame" "a.dat" |
| 436 | |
| 437 | git lfs lock --json "b.dat" | tee lock.log |
| 438 | id=$(assert_lock lock.log b.dat) |
| 439 | assert_server_lock "$reponame" "$id" |
| 440 | |
| 441 | git lfs unlock --force "b.dat" 2>&1 | tee unlock.log |
| 442 | refute_server_lock "$reponame" "$id" |
| 443 | ) |
| 444 | end_test |
| 445 | |
| 446 | begin_test "unlocking unlockable file" |
| 447 | ( |
| 448 | set -e |
| 449 | |
| 450 | reponame="unlock-unlockable-file" |
| 451 | # Try with lockable patterns. |
| 452 | setup_repo "$reponame" "a.dat" |
| 453 | |
| 454 | touch README.md |
| 455 | git add README.md |
| 456 | git commit -m 'Add README' |
| 457 | |
| 458 | git lfs lock --json "README.md" | tee lock.log |
| 459 | id=$(assert_lock lock.log README.md) |
| 460 | assert_server_lock "$reponame" "$id" |
| 461 | assert_file_writeable "README.md" |
| 462 | |
| 463 | git lfs unlock --force "README.md" 2>&1 | tee unlock.log |
| 464 | refute_server_lock "$reponame" "$id" |
| 465 | assert_file_writeable "README.md" |
| 466 | |
| 467 | cd "$TRASHDIR" |
| 468 | # Try without any lockable patterns. |
| 469 | setup_remote_repo_with_file "$reponame-2" "a.dat" |
| 470 | |
| 471 | touch README.md |
| 472 | git add README.md |
| 473 | git commit -m 'Add README' |
| 474 | |
| 475 | git lfs lock --json "README.md" | tee lock.log |
| 476 | id=$(assert_lock lock.log README.md) |
| 477 | assert_server_lock "$reponame-2" "$id" |
| 478 | assert_file_writeable "README.md" |
| 479 | |
| 480 | git lfs unlock --force "README.md" 2>&1 | tee unlock.log |
| 481 | refute_server_lock "$reponame-2" "$id" |
| 482 | assert_file_writeable "README.md" |
| 483 | ) |
| 484 | end_test |
| 485 | |
| 486 | begin_test "unlocking a lock (--json)" |
| 487 | ( |
| 488 | set -e |
| 489 | |
| 490 | reponame="unlock_by_path_json" |
| 491 | setup_repo "$reponame" "c_json.dat" |
| 492 | |
| 493 | git lfs lock --json "c_json.dat" | tee lock.log |
| 494 | |
| 495 | id=$(assert_lock lock.log c_json.dat) |
| 496 | assert_server_lock "$reponame" "$id" |
| 497 | |
| 498 | git lfs unlock --json "c_json.dat" 2>&1 | tee unlock.log |
| 499 | grep "\"unlocked\":true" unlock.log |
| 500 | |
| 501 | refute_server_lock "$reponame" "$id" |
| 502 | ) |
| 503 | end_test |
| 504 | |
| 505 | begin_test "unlocking a missing lockable file (--json)" |
| 506 | ( |
| 507 | set -e |
| 508 | |
| 509 | reponame="unlock_missing_lockable_path_json" |
| 510 | setup_remote_repo "$reponame" |
| 511 | clone_repo "$reponame" "$reponame" |
| 512 | |
| 513 | git lfs track --lockable "*.dat" |
| 514 | git add .gitattributes |
| 515 | git commit -m "Add lockable pattern" |
| 516 | git push origin main |
| 517 | |
| 518 | echo "file1.dat" > file1.dat |
| 519 | git lfs lock --json "file1.dat" | tee lock.log |
| 520 | |
| 521 | id=$(assert_lock lock.log file1.dat) |
| 522 | assert_server_lock "$reponame" "$id" |
| 523 | |
| 524 | rm file1.dat |
| 525 | |
| 526 | git lfs unlock --json "file1.dat" | tee unlock.log |
| 527 | [ 0 -eq "${PIPESTATUS[0]}" ] |
| 528 | |
| 529 | grep -F '[{"path":"file1.dat","unlocked":true}]' unlock.log |
| 530 | |
| 531 | refute_server_lock "$reponame" "$id" |
| 532 | ) |
| 533 | end_test |
| 534 | |
| 535 | begin_test "unlocking a lock by id" |
| 536 | ( |
| 537 | set -e |
| 538 | |
| 539 | reponame="unlock_by_id" |
| 540 | setup_repo "$reponame" "d.dat" |
| 541 | |
| 542 | git lfs lock --json "d.dat" | tee lock.log |
| 543 | assert_file_writeable d.dat |
| 544 | |
| 545 | id=$(assert_lock lock.log d.dat) |
| 546 | assert_server_lock "$reponame" "$id" |
| 547 | |
| 548 | git lfs unlock --id="$id" |
| 549 | refute_file_writeable d.dat |
| 550 | ) |
| 551 | end_test |
| 552 | |
| 553 | begin_test "unlocking a lock by id (--json)" |
| 554 | ( |
| 555 | set -e |
| 556 | |
| 557 | reponame="unlock_by_id_json" |
| 558 | setup_repo "$reponame" "c_json.dat" |
| 559 | |
| 560 | git lfs lock --json "c_json.dat" | tee lock.log |
| 561 | |
| 562 | id=$(assert_lock lock.log c_json.dat) |
| 563 | assert_server_lock "$reponame" "$id" |
| 564 | |
| 565 | git lfs unlock --json --id="$id" 2>&1 | tee unlock.log |
| 566 | grep "\"unlocked\":true" unlock.log |
| 567 | |
| 568 | refute_server_lock "$reponame" "$id" |
| 569 | ) |
| 570 | end_test |
| 571 | |
| 572 | begin_test "unlocking a lock without sufficient info" |
| 573 | ( |
| 574 | set -e |
| 575 | |
| 576 | reponame="unlock_ambiguous" |
| 577 | setup_repo "$reponame" "e.dat" |
| 578 | |
| 579 | git lfs lock --json "e.dat" | tee lock.log |
| 580 | |
| 581 | id=$(assert_lock lock.log e.dat) |
| 582 | assert_server_lock "$reponame" "$id" |
| 583 | |
| 584 | git lfs unlock 2>&1 | tee unlock.log |
| 585 | grep "Exactly one of --id or a set of paths must be provided" unlock.log |
| 586 | assert_server_lock "$reponame" "$id" |
| 587 | ) |
| 588 | end_test |
| 589 | |
| 590 | begin_test "unlocking a lock while uncommitted" |
| 591 | ( |
| 592 | set -e |
| 593 | |
| 594 | reponame="unlock_modified" |
| 595 | setup_repo "$reponame" "mod.dat" |
| 596 | |
| 597 | git lfs lock --json "mod.dat" | tee lock.log |
| 598 | |
| 599 | id=$(assert_lock lock.log mod.dat) |
| 600 | assert_server_lock "$reponame" "$id" |
| 601 | |
| 602 | echo "\nSomething" >> mod.dat |
| 603 | |
| 604 | git lfs unlock "mod.dat" 2>&1 | tee unlock.log |
| 605 | [ ${PIPESTATUS[0]} -ne "0" ] |
| 606 | |
| 607 | grep "Cannot unlock file with uncommitted changes" unlock.log |
| 608 | |
| 609 | assert_server_lock "$reponame" "$id" |
| 610 | |
| 611 | # should allow after discard |
| 612 | git checkout mod.dat |
| 613 | git lfs unlock "mod.dat" 2>&1 | tee unlock.log |
| 614 | refute_server_lock "$reponame" "$id" |
| 615 | ) |
| 616 | end_test |
| 617 | |
| 618 | begin_test "unlocking a lock with ambiguous arguments" |
| 619 | ( |
| 620 | set -e |
| 621 | |
| 622 | reponame="unlock_ambiguous_args" |
| 623 | setup_repo "$reponame" "a.dat" |
| 624 | |
| 625 | git lfs lock --json "a.dat" | tee lock.log |
| 626 | |
| 627 | id=$(assert_lock lock.log a.dat) |
| 628 | assert_server_lock "$reponame" "$id" |
| 629 | |
| 630 | git lfs unlock --id "$id" a.dat 2>&1 | tee unlock.log |
| 631 | if [ "0" -eq "${PIPESTATUS[0]}" ]; then |
| 632 | echo >&2 "expected ambiguous \`git lfs unlock\` command to exit, didn't" |
| 633 | exit 1 |
| 634 | fi |
| 635 | |
| 636 | grep "Exactly one of --id or a set of paths must be provided" unlock.log |
| 637 | assert_server_lock "$reponame" "$id" |
| 638 | ) |
| 639 | end_test |
| 640 | |
| 641 | begin_test "unlocking a lock while uncommitted with --force" |
| 642 | ( |
| 643 | set -e |
| 644 | |
| 645 | reponame="unlock_modified_force" |
| 646 | setup_repo "$reponame" "modforce.dat" |
| 647 | |
| 648 | git lfs lock --json "modforce.dat" | tee lock.log |
| 649 | |
| 650 | id=$(assert_lock lock.log modforce.dat) |
| 651 | assert_server_lock "$reponame" "$id" |
| 652 | |
| 653 | echo "\nSomething" >> modforce.dat |
| 654 | |
| 655 | # should allow with --force |
| 656 | git lfs unlock --force "modforce.dat" 2>&1 | tee unlock.log |
| 657 | grep "warning: unlocking with uncommitted changes" unlock.log |
| 658 | refute_server_lock "$reponame" "$id" |
| 659 | ) |
| 660 | end_test |
| 661 | |
| 662 | begin_test "unlocking a lock while untracked" |
| 663 | ( |
| 664 | set -e |
| 665 | |
| 666 | reponame="unlock_untracked" |
| 667 | setup_repo "$reponame" "notrelevant.dat" |
| 668 | |
| 669 | git lfs track "*.dat" |
| 670 | # Create file but don't add it to git |
| 671 | # Shouldn't be able to unlock it |
| 672 | echo "something" > untracked.dat |
| 673 | git lfs lock --json "untracked.dat" | tee lock.log |
| 674 | |
| 675 | id=$(assert_lock lock.log untracked.dat) |
| 676 | assert_server_lock "$reponame" "$id" |
| 677 | |
| 678 | git lfs unlock "untracked.dat" 2>&1 | tee unlock.log |
| 679 | [ ${PIPESTATUS[0]} -ne "0" ] |
| 680 | |
| 681 | grep "Cannot unlock file with uncommitted changes" unlock.log |
| 682 | |
| 683 | assert_server_lock "$reponame" "$id" |
| 684 | |
| 685 | # should allow after add/commit |
| 686 | git add untracked.dat |
| 687 | git commit -m "Added untracked" |
| 688 | git lfs unlock "untracked.dat" 2>&1 | tee unlock.log |
| 689 | refute_server_lock "$reponame" "$id" |
| 690 | ) |
| 691 | end_test |
| 692 | |
| 693 | begin_test "unlock with git-lfs-transfer" |
| 694 | ( |
| 695 | set -e |
| 696 | |
| 697 | setup_pure_ssh |
| 698 | |
| 699 | reponame="unlock-git-lfs-transfer" |
| 700 | setup_remote_repo_with_file "$reponame" "f.dat" |
| 701 | clone_repo "$reponame" "$reponame" |
| 702 | |
| 703 | sshurl=$(ssh_remote "$reponame") |
| 704 | git config lfs.url "$sshurl" |
| 705 | |
| 706 | GIT_TRACE_PACKET=1 git lfs lock --json "f.dat" | tee lock.log |
| 707 | |
| 708 | id=$(assert_lock lock.log f.dat) |
| 709 | assert_server_lock_ssh "$reponame" "$id" "refs/heads/main" |
| 710 | |
| 711 | git lfs unlock --id "$id" |
| 712 | refute_server_lock_ssh "$reponame" "$id" "refs/heads/main" |
| 713 | ) |
| 714 | end_test |