| 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | . "$(dirname "$0")/fixtures/migrate.sh" |
| 4 | . "$(dirname "$0")/testlib.sh" |
| 5 | |
| 6 | begin_test "migrate export (default branch)" |
| 7 | ( |
| 8 | set -e |
| 9 | |
| 10 | setup_multiple_local_branches_tracked |
| 11 | |
| 12 | # Add b.md, a pointer existing only on main |
| 13 | lfstest-genrandom --base64 160 >b.md |
| 14 | git add b.md |
| 15 | git commit -m "add b.md" |
| 16 | |
| 17 | md_oid="$(calc_oid "$(cat a.md)")" |
| 18 | txt_oid="$(calc_oid "$(cat a.txt)")" |
| 19 | b_md_oid="$(calc_oid "$(cat b.md)")" |
| 20 | |
| 21 | git checkout my-feature |
| 22 | md_feature_oid="$(calc_oid "$(cat a.md)")" |
| 23 | git checkout main |
| 24 | |
| 25 | assert_pointer "refs/heads/main" "a.md" "$md_oid" "140" |
| 26 | assert_pointer "refs/heads/main" "a.txt" "$txt_oid" "120" |
| 27 | assert_pointer "refs/heads/main" "b.md" "$b_md_oid" "160" |
| 28 | assert_pointer "refs/heads/my-feature" "a.md" "$md_feature_oid" "30" |
| 29 | |
| 30 | git lfs migrate export --include="*.md, *.txt" |
| 31 | |
| 32 | refute_pointer "refs/heads/main" "a.md" |
| 33 | refute_pointer "refs/heads/main" "a.txt" |
| 34 | refute_pointer "refs/heads/main" "b.md" |
| 35 | assert_pointer "refs/heads/my-feature" "a.md" "$md_feature_oid" "30" |
| 36 | |
| 37 | # b.md should be pruned as no pointer exists to reference it |
| 38 | refute_local_object "$b_md_oid" "160" |
| 39 | |
| 40 | # Other objects should not be pruned as they're still referenced in `feature` |
| 41 | # by pointers |
| 42 | assert_local_object "$md_oid" "140" |
| 43 | assert_local_object "$txt_oid" "120" |
| 44 | assert_local_object "$md_feature_oid" "30" |
| 45 | |
| 46 | main="$(git rev-parse refs/heads/main)" |
| 47 | feature="$(git rev-parse refs/heads/my-feature)" |
| 48 | |
| 49 | main_attrs="$(git cat-file -p "$main:.gitattributes")" |
| 50 | feature_attrs="$(git cat-file -p "$feature:.gitattributes")" |
| 51 | |
| 52 | echo "$main_attrs" | grep -q "*.md !text !filter !merge !diff" |
| 53 | echo "$main_attrs" | grep -q "*.txt !text !filter !merge !diff" |
| 54 | |
| 55 | echo "$feature_attrs" | grep -q "*.md !text !filter !merge !diff" && exit 1 |
| 56 | echo "$feature_attrs" | grep -q "*.txt !text !filter !merge !diff" && exit 1 |
| 57 | true |
| 58 | ) |
| 59 | end_test |
| 60 | |
| 61 | begin_test "migrate export (with remote)" |
| 62 | ( |
| 63 | set -e |
| 64 | |
| 65 | setup_single_remote_branch_tracked |
| 66 | |
| 67 | git push origin main |
| 68 | |
| 69 | md_oid="$(calc_oid "$(cat a.md)")" |
| 70 | txt_oid="$(calc_oid "$(cat a.txt)")" |
| 71 | |
| 72 | assert_pointer "refs/heads/main" "a.md" "$md_oid" "50" |
| 73 | assert_pointer "refs/heads/main" "a.txt" "$txt_oid" "30" |
| 74 | |
| 75 | assert_pointer "refs/remotes/origin/main" "a.md" "$md_oid" "50" |
| 76 | assert_pointer "refs/remotes/origin/main" "a.txt" "$txt_oid" "30" |
| 77 | |
| 78 | # Flush the cache to ensure all objects have to be downloaded |
| 79 | rm -rf .git/lfs/objects |
| 80 | |
| 81 | git lfs migrate export --everything --include="*.md, *.txt" |
| 82 | |
| 83 | refute_pointer "refs/heads/main" "a.md" |
| 84 | refute_pointer "refs/heads/main" "a.txt" |
| 85 | |
| 86 | # All pointers have been exported, so all objects should be pruned |
| 87 | refute_local_object "$md_oid" "50" |
| 88 | refute_local_object "$txt_oid" "30" |
| 89 | |
| 90 | main="$(git rev-parse refs/heads/main)" |
| 91 | main_attrs="$(git cat-file -p "$main:.gitattributes")" |
| 92 | |
| 93 | echo "$main_attrs" | grep -q "*.md !text !filter !merge !diff" |
| 94 | echo "$main_attrs" | grep -q "*.txt !text !filter !merge !diff" |
| 95 | ) |
| 96 | end_test |
| 97 | |
| 98 | begin_test "migrate export (include/exclude args)" |
| 99 | ( |
| 100 | set -e |
| 101 | |
| 102 | setup_single_local_branch_tracked |
| 103 | |
| 104 | md_oid="$(calc_oid "$(cat a.md)")" |
| 105 | txt_oid="$(calc_oid "$(cat a.txt)")" |
| 106 | |
| 107 | assert_pointer "refs/heads/main" "a.txt" "$txt_oid" "120" |
| 108 | assert_pointer "refs/heads/main" "a.md" "$md_oid" "140" |
| 109 | |
| 110 | git lfs migrate export --include="*" --exclude="a.md" |
| 111 | |
| 112 | refute_pointer "refs/heads/main" "a.txt" |
| 113 | assert_pointer "refs/heads/main" "a.md" "$md_oid" "140" |
| 114 | |
| 115 | refute_local_object "$txt_oid" "120" |
| 116 | assert_local_object "$md_oid" "140" |
| 117 | |
| 118 | main="$(git rev-parse refs/heads/main)" |
| 119 | |
| 120 | main_attrs="$(git cat-file -p "$main:.gitattributes")" |
| 121 | |
| 122 | echo "$main_attrs" | grep -q "* !text !filter !merge !diff" |
| 123 | echo "$main_attrs" | grep -q "a.md filter=lfs diff=lfs merge=lfs" |
| 124 | ) |
| 125 | end_test |
| 126 | |
| 127 | begin_test "migrate export (bare repository)" |
| 128 | ( |
| 129 | set -e |
| 130 | |
| 131 | setup_single_remote_branch_tracked |
| 132 | git push origin main |
| 133 | |
| 134 | md_oid="$(calc_oid "$(cat a.md)")" |
| 135 | txt_oid="$(calc_oid "$(cat a.txt)")" |
| 136 | |
| 137 | make_bare |
| 138 | |
| 139 | assert_pointer "refs/heads/main" "a.txt" "$txt_oid" "30" |
| 140 | assert_pointer "refs/heads/main" "a.md" "$md_oid" "50" |
| 141 | |
| 142 | git lfs migrate export --everything --include="*" |
| 143 | |
| 144 | refute_pointer "refs/heads/main" "a.md" |
| 145 | refute_pointer "refs/heads/main" "a.txt" |
| 146 | |
| 147 | # All pointers have been exported, so all objects should be pruned |
| 148 | refute_local_object "$md_oid" "50" |
| 149 | refute_local_object "$txt_oid" "30" |
| 150 | ) |
| 151 | end_test |
| 152 | |
| 153 | begin_test "migrate export (given branch)" |
| 154 | ( |
| 155 | set -e |
| 156 | |
| 157 | setup_multiple_local_branches_tracked |
| 158 | |
| 159 | md_oid="$(calc_oid "$(cat a.md)")" |
| 160 | txt_oid="$(calc_oid "$(cat a.txt)")" |
| 161 | |
| 162 | git checkout my-feature |
| 163 | md_feature_oid="$(calc_oid "$(cat a.md)")" |
| 164 | git checkout main |
| 165 | |
| 166 | assert_pointer "refs/heads/my-feature" "a.md" "$md_feature_oid" "30" |
| 167 | assert_pointer "refs/heads/my-feature" "a.txt" "$txt_oid" "120" |
| 168 | assert_pointer "refs/heads/main" "a.md" "$md_oid" "140" |
| 169 | assert_pointer "refs/heads/main" "a.txt" "$txt_oid" "120" |
| 170 | |
| 171 | git lfs migrate export --include="*.md,*.txt" my-feature |
| 172 | |
| 173 | refute_pointer "refs/heads/my-feature" "a.md" |
| 174 | refute_pointer "refs/heads/my-feature" "a.txt" |
| 175 | refute_pointer "refs/heads/main" "a.md" |
| 176 | refute_pointer "refs/heads/main" "a.txt" |
| 177 | |
| 178 | # No pointers left, so all objects should be pruned |
| 179 | refute_local_object "$md_feature_oid" "30" |
| 180 | refute_local_object "$txt_oid" "120" |
| 181 | refute_local_object "$md_oid" "140" |
| 182 | |
| 183 | main="$(git rev-parse refs/heads/main)" |
| 184 | feature="$(git rev-parse refs/heads/my-feature)" |
| 185 | |
| 186 | main_attrs="$(git cat-file -p "$main:.gitattributes")" |
| 187 | feature_attrs="$(git cat-file -p "$feature:.gitattributes")" |
| 188 | |
| 189 | echo "$main_attrs" | grep -q "*.md !text !filter !merge !diff" |
| 190 | echo "$main_attrs" | grep -q "*.txt !text !filter !merge !diff" |
| 191 | echo "$feature_attrs" | grep -q "*.md !text !filter !merge !diff" |
| 192 | echo "$feature_attrs" | grep -q "*.txt !text !filter !merge !diff" |
| 193 | ) |
| 194 | end_test |
| 195 | |
| 196 | begin_test "migrate export (no filter)" |
| 197 | ( |
| 198 | set -e |
| 199 | |
| 200 | setup_multiple_local_branches_tracked |
| 201 | |
| 202 | git lfs migrate export --yes 2>&1 | tee migrate.log |
| 203 | if [ ${PIPESTATUS[0]} -eq 0 ]; then |
| 204 | echo >&2 "fatal: expected git lfs migrate export to fail, didn't" |
| 205 | exit 1 |
| 206 | fi |
| 207 | |
| 208 | grep "One or more files must be specified with --include" migrate.log |
| 209 | ) |
| 210 | end_test |
| 211 | |
| 212 | begin_test "migrate export (exclude remote refs)" |
| 213 | ( |
| 214 | set -e |
| 215 | |
| 216 | setup_single_remote_branch_tracked |
| 217 | |
| 218 | md_oid="$(calc_oid "$(cat a.md)")" |
| 219 | txt_oid="$(calc_oid "$(cat a.txt)")" |
| 220 | |
| 221 | git checkout refs/remotes/origin/main |
| 222 | md_remote_oid="$(calc_oid "$(cat a.md)")" |
| 223 | txt_remote_oid="$(calc_oid "$(cat a.txt)")" |
| 224 | git checkout main |
| 225 | |
| 226 | assert_pointer "refs/heads/main" "a.md" "$md_oid" "50" |
| 227 | assert_pointer "refs/heads/main" "a.txt" "$txt_oid" "30" |
| 228 | |
| 229 | assert_pointer "refs/remotes/origin/main" "a.md" "$md_remote_oid" "140" |
| 230 | assert_pointer "refs/remotes/origin/main" "a.txt" "$txt_remote_oid" "120" |
| 231 | |
| 232 | git lfs migrate export --include="*.md,*.txt" |
| 233 | |
| 234 | refute_pointer "refs/heads/main" "a.md" |
| 235 | refute_pointer "refs/heads/main" "a.txt" |
| 236 | |
| 237 | refute_local_object "$md_oid" "50" |
| 238 | refute_local_object "$txt_oid" "30" |
| 239 | |
| 240 | assert_pointer "refs/remotes/origin/main" "a.md" "$md_remote_oid" "140" |
| 241 | assert_pointer "refs/remotes/origin/main" "a.txt" "$txt_remote_oid" "120" |
| 242 | |
| 243 | # Since these two objects exist on the remote, they should be removed with |
| 244 | # our prune operation |
| 245 | refute_local_object "$md_remote_oid" "140" |
| 246 | refute_local_object "$txt_remote_oid" "120" |
| 247 | |
| 248 | main="$(git rev-parse refs/heads/main)" |
| 249 | remote="$(git rev-parse refs/remotes/origin/main)" |
| 250 | |
| 251 | main_attrs="$(git cat-file -p "$main:.gitattributes")" |
| 252 | remote_attrs="$(git cat-file -p "$remote:.gitattributes")" |
| 253 | |
| 254 | echo "$main_attrs" | grep -q "*.md !text !filter !merge !diff" |
| 255 | echo "$main_attrs" | grep -q "*.txt !text !filter !merge !diff" |
| 256 | |
| 257 | echo "$remote_attrs" | grep -q "*.md !text !filter !merge !diff" && exit 1 |
| 258 | echo "$remote_attrs" | grep -q "*.txt !text !filter !merge !diff" && exit 1 |
| 259 | true |
| 260 | ) |
| 261 | end_test |
| 262 | |
| 263 | begin_test "migrate export (--skip-fetch)" |
| 264 | ( |
| 265 | set -e |
| 266 | |
| 267 | setup_single_remote_branch_tracked |
| 268 | |
| 269 | md_main_oid="$(calc_oid "$(cat a.md)")" |
| 270 | txt_main_oid="$(calc_oid "$(cat a.txt)")" |
| 271 | |
| 272 | git checkout refs/remotes/origin/main |
| 273 | md_remote_oid="$(calc_oid "$(cat a.md)")" |
| 274 | txt_remote_oid="$(calc_oid "$(cat a.txt)")" |
| 275 | git checkout main |
| 276 | |
| 277 | git tag pseudo-remote "$(git rev-parse refs/remotes/origin/main)" |
| 278 | # Remove the refs/remotes/origin/main ref, and instruct 'git lfs migrate' to |
| 279 | # not fetch it. |
| 280 | git update-ref -d refs/remotes/origin/main |
| 281 | |
| 282 | assert_pointer "refs/heads/main" "a.md" "$md_main_oid" "50" |
| 283 | assert_pointer "pseudo-remote" "a.md" "$md_remote_oid" "140" |
| 284 | assert_pointer "refs/heads/main" "a.txt" "$txt_main_oid" "30" |
| 285 | assert_pointer "pseudo-remote" "a.txt" "$txt_remote_oid" "120" |
| 286 | |
| 287 | git lfs migrate export --skip-fetch --include="*.md,*.txt" |
| 288 | |
| 289 | refute_pointer "refs/heads/main" "a.md" |
| 290 | refute_pointer "pseudo-remote" "a.md" |
| 291 | refute_pointer "refs/heads/main" "a.txt" |
| 292 | refute_pointer "pseudo-remote" "a.txt" |
| 293 | |
| 294 | refute_local_object "$md_main_oid" "50" |
| 295 | refute_local_object "$md_remote_oid" "140" |
| 296 | refute_local_object "$txt_main_oid" "30" |
| 297 | refute_local_object "$txt_remote_oid" "120" |
| 298 | |
| 299 | main="$(git rev-parse refs/heads/main)" |
| 300 | remote="$(git rev-parse pseudo-remote)" |
| 301 | |
| 302 | main_attrs="$(git cat-file -p "$main:.gitattributes")" |
| 303 | remote_attrs="$(git cat-file -p "$remote:.gitattributes")" |
| 304 | |
| 305 | echo "$main_attrs" | grep -q "*.md !text !filter !merge !diff" |
| 306 | echo "$main_attrs" | grep -q "*.txt !text !filter !merge !diff" |
| 307 | echo "$remote_attrs" | grep -q "*.md !text !filter !merge !diff" |
| 308 | echo "$remote_attrs" | grep -q "*.txt !text !filter !merge !diff" |
| 309 | ) |
| 310 | end_test |
| 311 | |
| 312 | begin_test "migrate export (include/exclude ref)" |
| 313 | ( |
| 314 | set -e |
| 315 | |
| 316 | setup_multiple_remote_branches_gitattrs |
| 317 | |
| 318 | md_main_oid="$(calc_oid "$(cat a.md)")" |
| 319 | txt_main_oid="$(calc_oid "$(cat a.txt)")" |
| 320 | |
| 321 | git checkout refs/remotes/origin/main |
| 322 | md_remote_oid="$(calc_oid "$(cat a.md)")" |
| 323 | txt_remote_oid="$(calc_oid "$(cat a.txt)")" |
| 324 | |
| 325 | git checkout my-feature |
| 326 | md_feature_oid="$(calc_oid "$(cat a.md)")" |
| 327 | txt_feature_oid="$(calc_oid "$(cat a.txt)")" |
| 328 | |
| 329 | git checkout main |
| 330 | |
| 331 | git lfs migrate export \ |
| 332 | --include="*.txt" \ |
| 333 | --include-ref=refs/heads/my-feature \ |
| 334 | --exclude-ref=refs/heads/main |
| 335 | |
| 336 | assert_pointer "refs/heads/main" "a.md" "$md_main_oid" "21" |
| 337 | assert_pointer "refs/heads/main" "a.txt" "$txt_main_oid" "20" |
| 338 | |
| 339 | assert_pointer "refs/remotes/origin/main" "a.md" "$md_remote_oid" "11" |
| 340 | assert_pointer "refs/remotes/origin/main" "a.txt" "$txt_remote_oid" "10" |
| 341 | |
| 342 | assert_pointer "refs/heads/my-feature" "a.md" "$md_feature_oid" "31" |
| 343 | refute_pointer "refs/heads/my-feature" "a.txt" |
| 344 | |
| 345 | # Master objects should not be pruned as they exist in unpushed commits |
| 346 | assert_local_object "$md_main_oid" "21" |
| 347 | assert_local_object "$txt_main_oid" "20" |
| 348 | |
| 349 | # Remote main objects should be pruned as they exist in the remote |
| 350 | refute_local_object "$md_remote_oid" "11" |
| 351 | refute_local_object "$txt_remote_oid" "10" |
| 352 | |
| 353 | # txt_feature_oid should be pruned as it's no longer a pointer, but |
| 354 | # md_feature_oid should remain as it's still a pointer in unpushed commits |
| 355 | assert_local_object "$md_feature_oid" "31" |
| 356 | refute_local_object "$txt_feature_oid" "30" |
| 357 | |
| 358 | main="$(git rev-parse refs/heads/main)" |
| 359 | feature="$(git rev-parse refs/heads/my-feature)" |
| 360 | remote="$(git rev-parse refs/remotes/origin/main)" |
| 361 | |
| 362 | main_attrs="$(git cat-file -p "$main:.gitattributes")" |
| 363 | remote_attrs="$(git cat-file -p "$remote:.gitattributes")" |
| 364 | feature_attrs="$(git cat-file -p "$feature:.gitattributes")" |
| 365 | |
| 366 | echo "$main_attrs" | grep -q "*.txt !text !filter !merge !diff" && exit 1 |
| 367 | echo "$remote_attrs" | grep -q "*.txt !text !filter !merge !diff" && exit 1 |
| 368 | echo "$feature_attrs" | grep -q "*.txt !text !filter !merge !diff" |
| 369 | ) |
| 370 | end_test |
| 371 | |
| 372 | begin_test "migrate export (invalid ref)" |
| 373 | ( |
| 374 | set -e |
| 375 | remove_and_create_local_repo "migrate-export-invalid-ref" |
| 376 | git commit --allow-empty -m "initial commit" |
| 377 | |
| 378 | git lfs migrate export --yes --include="*" jibberish >migrate.log 2>&1 && exit 1 |
| 379 | grep "can't resolve ref" migrate.log |
| 380 | ) |
| 381 | end_test |
| 382 | |
| 383 | begin_test "migrate export (.gitattributes with different permissions)" |
| 384 | ( |
| 385 | set -e |
| 386 | |
| 387 | # Windows lacks POSIX permissions. |
| 388 | [ "$IS_WINDOWS" -eq 1 ] && exit 0 |
| 389 | |
| 390 | setup_single_local_branch_tracked 0755 |
| 391 | |
| 392 | md_oid="$(calc_oid "$(cat a.md)")" |
| 393 | txt_oid="$(calc_oid "$(cat a.txt)")" |
| 394 | |
| 395 | assert_pointer "refs/heads/main" "a.txt" "$txt_oid" "120" |
| 396 | assert_pointer "refs/heads/main" "a.md" "$md_oid" "140" |
| 397 | |
| 398 | [ -x .gitattributes ] |
| 399 | |
| 400 | git lfs migrate export --include="*.txt" |
| 401 | |
| 402 | [ ! -x .gitattributes ] |
| 403 | |
| 404 | refute_pointer "refs/heads/main" "a.txt" |
| 405 | assert_pointer "refs/heads/main" "a.md" "$md_oid" "140" |
| 406 | |
| 407 | refute_local_object "$txt_oid" "120" |
| 408 | assert_local_object "$md_oid" "140" |
| 409 | |
| 410 | main="$(git rev-parse refs/heads/main)" |
| 411 | |
| 412 | main_attrs="$(git cat-file -p "$main:.gitattributes")" |
| 413 | |
| 414 | echo "$main_attrs" | grep -q "*.txt !text !filter !merge !diff" |
| 415 | |
| 416 | attrs_main_sha="$(git show $main:.gitattributes | git hash-object --stdin)" |
| 417 | md_main_sha="$(git show $main:a.md | git hash-object --stdin)" |
| 418 | txt_main_sha="$(git show $main:a.txt | git hash-object --stdin)" |
| 419 | |
| 420 | diff -u <(git ls-tree $main) <(cat <<-EOF |
| 421 | 100644 blob $attrs_main_sha .gitattributes |
| 422 | 100644 blob $md_main_sha a.md |
| 423 | 100644 blob $txt_main_sha a.txt |
| 424 | EOF |
| 425 | ) |
| 426 | ) |
| 427 | end_test |
| 428 | |
| 429 | begin_test "migrate export (.gitattributes symlink)" |
| 430 | ( |
| 431 | set -e |
| 432 | |
| 433 | setup_single_local_branch_tracked link |
| 434 | |
| 435 | git lfs migrate export --yes --include="*.txt" 2>&1 | tee migrate.log |
| 436 | if [ ${PIPESTATUS[0]} -eq 0 ]; then |
| 437 | echo >&2 "fatal: expected git lfs migrate export to fail, didn't" |
| 438 | exit 1 |
| 439 | fi |
| 440 | |
| 441 | grep "expected '.gitattributes' to be a file, got a symbolic link" migrate.log |
| 442 | |
| 443 | main="$(git rev-parse refs/heads/main)" |
| 444 | |
| 445 | attrs_main_sha="$(git show $main:.gitattributes | git hash-object --stdin)" |
| 446 | |
| 447 | diff -u <(git ls-tree $main -- .gitattributes) <(cat <<-EOF |
| 448 | 120000 blob $attrs_main_sha .gitattributes |
| 449 | EOF |
| 450 | ) |
| 451 | ) |
| 452 | end_test |
| 453 | |
| 454 | begin_test "migrate export (--object-map)" |
| 455 | ( |
| 456 | set -e |
| 457 | |
| 458 | setup_multiple_local_branches_tracked |
| 459 | |
| 460 | output_dir="$GIT_LFS_TEST_DIR/export-object-map-$(lfstest-genrandom --base64url 32)" |
| 461 | mkdir -p "$output_dir" |
| 462 | |
| 463 | git log --all --pretty='format:%H' > "${output_dir}/old_sha.txt" |
| 464 | git lfs migrate export --everything --include="*" --object-map "${output_dir}/object-map.txt" |
| 465 | git log --all --pretty='format:%H' > "${output_dir}/new_sha.txt" |
| 466 | paste -d',' "${output_dir}/old_sha.txt" "${output_dir}/new_sha.txt" > "${output_dir}/expected-map.txt" |
| 467 | |
| 468 | diff -u <(sort "${output_dir}/expected-map.txt") <(sort "${output_dir}/object-map.txt") |
| 469 | ) |
| 470 | end_test |
| 471 | |
| 472 | begin_test "migrate export (--verbose)" |
| 473 | ( |
| 474 | set -e |
| 475 | |
| 476 | setup_multiple_local_branches_tracked |
| 477 | |
| 478 | original_head="$(git rev-parse HEAD)" |
| 479 | |
| 480 | git lfs migrate export --everything --include="*" --verbose --yes 2>&1 | tee migrate.log |
| 481 | grep -q " commit ${original_head}: a\.md" migrate.log |
| 482 | ) |
| 483 | end_test |
| 484 | |
| 485 | begin_test "migrate export (--remote)" |
| 486 | ( |
| 487 | set -e |
| 488 | |
| 489 | setup_single_remote_branch_tracked |
| 490 | |
| 491 | git push origin main |
| 492 | |
| 493 | md_oid="$(calc_oid "$(cat a.md)")" |
| 494 | txt_oid="$(calc_oid "$(cat a.txt)")" |
| 495 | |
| 496 | assert_pointer "refs/heads/main" "a.md" "$md_oid" "50" |
| 497 | assert_pointer "refs/heads/main" "a.txt" "$txt_oid" "30" |
| 498 | |
| 499 | # Flush the cache to ensure all objects have to be downloaded |
| 500 | rm -rf .git/lfs/objects |
| 501 | |
| 502 | # Setup a new remote and invalidate the default |
| 503 | remote_url="$(git config --get remote.origin.url)" |
| 504 | git remote add zeta "$remote_url" |
| 505 | git remote set-url origin "" |
| 506 | |
| 507 | git lfs migrate export --everything --remote="zeta" --include="*.md, *.txt" |
| 508 | |
| 509 | refute_pointer "refs/heads/main" "a.md" |
| 510 | refute_pointer "refs/heads/main" "a.txt" |
| 511 | |
| 512 | refute_local_object "$md_oid" "50" |
| 513 | refute_local_object "$txt_oid" "30" |
| 514 | ) |
| 515 | end_test |
| 516 | |
| 517 | begin_test "migrate export (invalid --remote)" |
| 518 | ( |
| 519 | set -e |
| 520 | |
| 521 | setup_single_remote_branch_tracked |
| 522 | |
| 523 | git lfs migrate export --include="*" --remote="zz" --yes 2>&1 \ |
| 524 | | tee migrate.log |
| 525 | if [ ${PIPESTATUS[0]} -eq 0 ]; then |
| 526 | echo >&2 "fatal: expected git lfs migrate export to fail, didn't" |
| 527 | exit 1 |
| 528 | fi |
| 529 | |
| 530 | grep "Invalid remote zz provided" migrate.log |
| 531 | ) |
| 532 | end_test |
| 533 | |
| 534 | begin_test "migrate export (invalid pointer)" |
| 535 | ( |
| 536 | set -e |
| 537 | |
| 538 | git init repo1 |
| 539 | git init repo2 |
| 540 | |
| 541 | cd repo1 |
| 542 | echo "git-lfs" > problematic_file |
| 543 | git add . |
| 544 | git commit -m "create repo" |
| 545 | |
| 546 | git lfs migrate export --include="*" --everything --yes |
| 547 | |
| 548 | cd ../repo2 |
| 549 | echo "not git-lfs" > problematic_file |
| 550 | git add . |
| 551 | git commit -m "create repo" |
| 552 | |
| 553 | git lfs migrate export --include="*" --everything --yes |
| 554 | ) |
| 555 | end_test |