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