| 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | . "$(dirname "$0")/fixtures/migrate.sh" |
| 4 | . "$(dirname "$0")/testlib.sh" |
| 5 | |
| 6 | begin_test "migrate import (default branch)" |
| 7 | ( |
| 8 | set -e |
| 9 | |
| 10 | setup_multiple_local_branches |
| 11 | |
| 12 | md_oid="$(calc_oid "$(git cat-file -p :a.md)")" |
| 13 | txt_oid="$(calc_oid "$(git cat-file -p :a.txt)")" |
| 14 | md_feature_oid="$(calc_oid "$(git cat-file -p my-feature:a.md)")" |
| 15 | |
| 16 | git lfs migrate import |
| 17 | |
| 18 | assert_pointer "refs/heads/main" "a.md" "$md_oid" "140" |
| 19 | assert_pointer "refs/heads/main" "a.txt" "$txt_oid" "120" |
| 20 | |
| 21 | assert_local_object "$md_oid" "140" |
| 22 | assert_local_object "$txt_oid" "120" |
| 23 | refute_local_object "$md_feature_oid" "30" |
| 24 | |
| 25 | main="$(git rev-parse refs/heads/main)" |
| 26 | feature="$(git rev-parse refs/heads/my-feature)" |
| 27 | |
| 28 | main_attrs="$(git cat-file -p "$main:.gitattributes")" |
| 29 | [ -z "$(git cat-file -p "$feature:.gitattributes")" ] |
| 30 | |
| 31 | echo "$main_attrs" | grep -q "*.md filter=lfs diff=lfs merge=lfs" |
| 32 | echo "$main_attrs" | grep -q "*.txt filter=lfs diff=lfs merge=lfs" |
| 33 | |
| 34 | # Ensure that hooks are installed. If we find 'git-lfs' somewhere in |
| 35 | # .git/hooks/pre-push we assume that the rest went correctly, too. |
| 36 | grep -q "git-lfs" .git/hooks/pre-push |
| 37 | ) |
| 38 | end_test |
| 39 | |
| 40 | begin_test "migrate import (bare repository)" |
| 41 | ( |
| 42 | set -e |
| 43 | |
| 44 | setup_multiple_remote_branches |
| 45 | |
| 46 | git lfs migrate import --everything |
| 47 | ) |
| 48 | end_test |
| 49 | |
| 50 | begin_test "migrate import (given branch)" |
| 51 | ( |
| 52 | set -e |
| 53 | |
| 54 | setup_multiple_local_branches |
| 55 | |
| 56 | md_oid="$(calc_oid "$(git cat-file -p :a.md)")" |
| 57 | txt_oid="$(calc_oid "$(git cat-file -p :a.txt)")" |
| 58 | md_feature_oid="$(calc_oid "$(git cat-file -p my-feature:a.md)")" |
| 59 | |
| 60 | git lfs migrate import my-feature |
| 61 | |
| 62 | assert_pointer "refs/heads/my-feature" "a.md" "$md_feature_oid" "30" |
| 63 | assert_pointer "refs/heads/my-feature" "a.txt" "$txt_oid" "120" |
| 64 | assert_pointer "refs/heads/main" "a.md" "$md_oid" "140" |
| 65 | assert_pointer "refs/heads/main" "a.txt" "$txt_oid" "120" |
| 66 | |
| 67 | assert_local_object "$md_oid" "140" |
| 68 | assert_local_object "$md_feature_oid" "30" |
| 69 | assert_local_object "$txt_oid" "120" |
| 70 | |
| 71 | main="$(git rev-parse refs/heads/main)" |
| 72 | feature="$(git rev-parse refs/heads/my-feature)" |
| 73 | |
| 74 | main_attrs="$(git cat-file -p "$main:.gitattributes")" |
| 75 | feature_attrs="$(git cat-file -p "$feature:.gitattributes")" |
| 76 | |
| 77 | echo "$main_attrs" | grep -q "*.md filter=lfs diff=lfs merge=lfs" |
| 78 | echo "$main_attrs" | grep -q "*.txt filter=lfs diff=lfs merge=lfs" |
| 79 | echo "$feature_attrs" | grep -q "*.md filter=lfs diff=lfs merge=lfs" |
| 80 | echo "$feature_attrs" | grep -q "*.txt filter=lfs diff=lfs merge=lfs" |
| 81 | ) |
| 82 | end_test |
| 83 | |
| 84 | begin_test "migrate import (default branch with filter)" |
| 85 | ( |
| 86 | set -e |
| 87 | |
| 88 | setup_multiple_local_branches |
| 89 | |
| 90 | md_oid="$(calc_oid "$(git cat-file -p :a.md)")" |
| 91 | txt_oid="$(calc_oid "$(git cat-file -p :a.txt)")" |
| 92 | md_feature_oid="$(calc_oid "$(git cat-file -p my-feature:a.md)")" |
| 93 | |
| 94 | git lfs migrate import --include "*.md" |
| 95 | |
| 96 | assert_pointer "refs/heads/main" "a.md" "$md_oid" "140" |
| 97 | |
| 98 | assert_local_object "$md_oid" "140" |
| 99 | refute_local_object "$txt_oid" "120" |
| 100 | refute_local_object "$md_feature_oid" "30" |
| 101 | |
| 102 | main="$(git rev-parse refs/heads/main)" |
| 103 | feature="$(git rev-parse refs/heads/my-feature)" |
| 104 | |
| 105 | main_attrs="$(git cat-file -p "$main:.gitattributes")" |
| 106 | [ -z "$(git cat-file -p "$feature:.gitattributes")" ] |
| 107 | |
| 108 | echo "$main_attrs" | grep -q "*.md filter=lfs diff=lfs merge=lfs" |
| 109 | [ 0 -eq "$(echo "$main_attrs" | grep -c "*.txt filter=lfs diff=lfs merge=lfs")" ] |
| 110 | ) |
| 111 | end_test |
| 112 | |
| 113 | begin_test "migrate import (given branch with filter)" |
| 114 | ( |
| 115 | set -e |
| 116 | |
| 117 | setup_multiple_local_branches |
| 118 | |
| 119 | md_oid="$(calc_oid "$(git cat-file -p :a.md)")" |
| 120 | txt_oid="$(calc_oid "$(git cat-file -p :a.txt)")" |
| 121 | md_feature_oid="$(calc_oid "$(git cat-file -p my-feature:a.md)")" |
| 122 | |
| 123 | git lfs migrate import --include "*.md" my-feature |
| 124 | |
| 125 | assert_pointer "refs/heads/my-feature" "a.md" "$md_feature_oid" "30" |
| 126 | assert_pointer "refs/heads/my-feature~1" "a.md" "$md_oid" "140" |
| 127 | |
| 128 | assert_local_object "$md_oid" "140" |
| 129 | assert_local_object "$md_feature_oid" "30" |
| 130 | refute_local_object "$txt_oid" "120" |
| 131 | |
| 132 | main="$(git rev-parse refs/heads/main)" |
| 133 | feature="$(git rev-parse refs/heads/my-feature)" |
| 134 | |
| 135 | main_attrs="$(git cat-file -p "$main:.gitattributes")" |
| 136 | feature_attrs="$(git cat-file -p "$feature:.gitattributes")" |
| 137 | |
| 138 | echo "$main_attrs" | grep -q "*.md filter=lfs diff=lfs merge=lfs" |
| 139 | [ 0 -eq "$(echo "$main_attrs" | grep -c "*.txt filter=lfs diff=lfs merge=lfs")" ] |
| 140 | echo "$feature_attrs" | grep -q "*.md filter=lfs diff=lfs merge=lfs" |
| 141 | [ 0 -eq "$(echo "$feature_attrs" | grep -c "*.txt filter=lfs diff=lfs merge=lfs")" ] |
| 142 | ) |
| 143 | end_test |
| 144 | |
| 145 | begin_test "migrate import (.git objects/symlink)" |
| 146 | ( |
| 147 | set -e |
| 148 | mkdir other |
| 149 | |
| 150 | setup_multiple_local_branches |
| 151 | |
| 152 | mv .git/objects ../other/ |
| 153 | ln -s ../../other/objects .git/objects |
| 154 | |
| 155 | md_oid="$(calc_oid "$(git cat-file -p :a.md)")" |
| 156 | txt_oid="$(calc_oid "$(git cat-file -p :a.txt)")" |
| 157 | md_feature_oid="$(calc_oid "$(git cat-file -p my-feature:a.md)")" |
| 158 | |
| 159 | git lfs migrate import |
| 160 | |
| 161 | assert_pointer "refs/heads/main" "a.md" "$md_oid" "140" |
| 162 | assert_pointer "refs/heads/main" "a.txt" "$txt_oid" "120" |
| 163 | |
| 164 | assert_local_object "$md_oid" "140" |
| 165 | assert_local_object "$txt_oid" "120" |
| 166 | refute_local_object "$md_feature_oid" "30" |
| 167 | ) |
| 168 | end_test |
| 169 | |
| 170 | begin_test "migrate import (default branch, exclude remote refs)" |
| 171 | ( |
| 172 | set -e |
| 173 | |
| 174 | setup_single_remote_branch |
| 175 | |
| 176 | md_remote_oid="$(calc_oid "$(git cat-file -p "refs/remotes/origin/main:a.md")")" |
| 177 | txt_remote_oid="$(calc_oid "$(git cat-file -p "refs/remotes/origin/main:a.txt")")" |
| 178 | md_oid="$(calc_oid "$(git cat-file -p "refs/heads/main:a.md")")" |
| 179 | txt_oid="$(calc_oid "$(git cat-file -p "refs/heads/main:a.txt")")" |
| 180 | |
| 181 | git lfs migrate import |
| 182 | |
| 183 | assert_pointer "refs/heads/main" "a.md" "$md_oid" "50" |
| 184 | assert_pointer "refs/heads/main" "a.txt" "$txt_oid" "30" |
| 185 | |
| 186 | assert_local_object "$md_oid" "50" |
| 187 | assert_local_object "$txt_oid" "30" |
| 188 | refute_local_object "$md_remote_oid" "140" |
| 189 | refute_local_object "$txt_remote_oid" "120" |
| 190 | |
| 191 | main="$(git rev-parse refs/heads/main)" |
| 192 | remote="$(git rev-parse refs/remotes/origin/main)" |
| 193 | |
| 194 | main_attrs="$(git cat-file -p "$main:.gitattributes")" |
| 195 | [ -z "$(git cat-file -p "$remote:.gitattributes")" ] |
| 196 | |
| 197 | echo "$main_attrs" | grep -q "*.md filter=lfs diff=lfs merge=lfs" |
| 198 | echo "$main_attrs" | grep -q "*.txt filter=lfs diff=lfs merge=lfs" |
| 199 | ) |
| 200 | end_test |
| 201 | |
| 202 | begin_test "migrate import (given branch, exclude remote refs)" |
| 203 | ( |
| 204 | set -e |
| 205 | |
| 206 | setup_multiple_remote_branches |
| 207 | |
| 208 | md_main_oid="$(calc_oid "$(git cat-file -p "refs/heads/main:a.md")")" |
| 209 | md_remote_oid="$(calc_oid "$(git cat-file -p "refs/remotes/origin/main:a.md")")" |
| 210 | md_feature_oid="$(calc_oid "$(git cat-file -p "refs/heads/my-feature:a.md")")" |
| 211 | txt_main_oid="$(calc_oid "$(git cat-file -p "refs/heads/main:a.txt")")" |
| 212 | txt_remote_oid="$(calc_oid "$(git cat-file -p "refs/remotes/origin/main:a.txt")")" |
| 213 | txt_feature_oid="$(calc_oid "$(git cat-file -p "refs/heads/my-feature:a.txt")")" |
| 214 | |
| 215 | git lfs migrate import my-feature |
| 216 | |
| 217 | assert_pointer "refs/heads/main" "a.md" "$md_main_oid" "21" |
| 218 | assert_pointer "refs/heads/my-feature" "a.md" "$md_feature_oid" "31" |
| 219 | assert_pointer "refs/heads/main" "a.txt" "$txt_main_oid" "20" |
| 220 | assert_pointer "refs/heads/my-feature" "a.txt" "$txt_feature_oid" "30" |
| 221 | |
| 222 | assert_local_object "$md_feature_oid" "31" |
| 223 | assert_local_object "$md_main_oid" "21" |
| 224 | assert_local_object "$txt_feature_oid" "30" |
| 225 | assert_local_object "$txt_main_oid" "20" |
| 226 | refute_local_object "$md_remote_oid" "11" |
| 227 | refute_local_object "$txt_remote_oid" "10" |
| 228 | |
| 229 | main="$(git rev-parse refs/heads/main)" |
| 230 | feature="$(git rev-parse refs/heads/my-feature)" |
| 231 | remote="$(git rev-parse refs/remotes/origin/main)" |
| 232 | |
| 233 | main_attrs="$(git cat-file -p "$main:.gitattributes")" |
| 234 | [ -z "$(git cat-file -p "$remote:.gitattributes")" ] |
| 235 | feature_attrs="$(git cat-file -p "$feature:.gitattributes")" |
| 236 | |
| 237 | echo "$main_attrs" | grep -q "*.md filter=lfs diff=lfs merge=lfs" |
| 238 | echo "$main_attrs" | grep -q "*.txt filter=lfs diff=lfs merge=lfs" |
| 239 | echo "$feature_attrs" | grep -q "*.md filter=lfs diff=lfs merge=lfs" |
| 240 | echo "$feature_attrs" | grep -q "*.txt filter=lfs diff=lfs merge=lfs" |
| 241 | ) |
| 242 | end_test |
| 243 | |
| 244 | begin_test "migrate import (given ref, --skip-fetch)" |
| 245 | ( |
| 246 | set -e |
| 247 | |
| 248 | setup_single_remote_branch |
| 249 | |
| 250 | md_main_oid="$(calc_oid "$(git cat-file -p "refs/heads/main:a.md")")" |
| 251 | md_remote_oid="$(calc_oid "$(git cat-file -p "refs/remotes/origin/main:a.md")")" |
| 252 | txt_main_oid="$(calc_oid "$(git cat-file -p "refs/heads/main:a.txt")")" |
| 253 | txt_remote_oid="$(calc_oid "$(git cat-file -p "refs/remotes/origin/main:a.txt")")" |
| 254 | |
| 255 | git tag pseudo-remote "$(git rev-parse refs/remotes/origin/main)" |
| 256 | # Remove the refs/remotes/origin/main ref, and instruct 'git lfs migrate' to |
| 257 | # not fetch it. |
| 258 | git update-ref -d refs/remotes/origin/main |
| 259 | |
| 260 | git lfs migrate import --skip-fetch |
| 261 | |
| 262 | assert_pointer "refs/heads/main" "a.md" "$md_main_oid" "50" |
| 263 | assert_pointer "pseudo-remote" "a.md" "$md_remote_oid" "140" |
| 264 | assert_pointer "refs/heads/main" "a.txt" "$txt_main_oid" "30" |
| 265 | assert_pointer "pseudo-remote" "a.txt" "$txt_remote_oid" "120" |
| 266 | |
| 267 | assert_local_object "$md_main_oid" "50" |
| 268 | assert_local_object "$txt_main_oid" "30" |
| 269 | assert_local_object "$md_remote_oid" "140" |
| 270 | assert_local_object "$txt_remote_oid" "120" |
| 271 | |
| 272 | main="$(git rev-parse refs/heads/main)" |
| 273 | remote="$(git rev-parse pseudo-remote)" |
| 274 | |
| 275 | main_attrs="$(git cat-file -p "$main:.gitattributes")" |
| 276 | remote_attrs="$(git cat-file -p "$remote:.gitattributes")" |
| 277 | |
| 278 | echo "$main_attrs" | grep -q "*.md filter=lfs diff=lfs merge=lfs" |
| 279 | echo "$main_attrs" | grep -q "*.txt filter=lfs diff=lfs merge=lfs" |
| 280 | echo "$remote_attrs" | grep -q "*.md filter=lfs diff=lfs merge=lfs" |
| 281 | echo "$remote_attrs" | grep -q "*.txt filter=lfs diff=lfs merge=lfs" |
| 282 | ) |
| 283 | end_test |
| 284 | |
| 285 | begin_test "migrate import (un-annotated tags)" |
| 286 | ( |
| 287 | set -e |
| 288 | |
| 289 | setup_single_local_branch_with_tags |
| 290 | |
| 291 | txt_main_oid="$(calc_oid "$(git cat-file -p "refs/heads/main:a.txt")")" |
| 292 | |
| 293 | git lfs migrate import --everything |
| 294 | |
| 295 | assert_pointer "refs/heads/main" "a.txt" "$txt_main_oid" "2" |
| 296 | assert_local_object "$txt_main_oid" "2" |
| 297 | |
| 298 | git tag --points-at "$(git rev-parse HEAD)" | grep -q "v1.0.0" |
| 299 | ) |
| 300 | end_test |
| 301 | |
| 302 | begin_test "migrate import (annotated tags)" |
| 303 | ( |
| 304 | set -e |
| 305 | |
| 306 | setup_single_local_branch_with_annotated_tags |
| 307 | |
| 308 | txt_main_oid="$(calc_oid "$(git cat-file -p "refs/heads/main:a.txt")")" |
| 309 | |
| 310 | git lfs migrate import --everything |
| 311 | |
| 312 | assert_pointer "refs/heads/main" "a.txt" "$txt_main_oid" "2" |
| 313 | assert_local_object "$txt_main_oid" "2" |
| 314 | |
| 315 | git tag --points-at "$(git rev-parse HEAD)" | grep -q "v1.0.0" |
| 316 | ) |
| 317 | end_test |
| 318 | |
| 319 | begin_test "migrate import (include/exclude ref)" |
| 320 | ( |
| 321 | set -e |
| 322 | |
| 323 | setup_multiple_remote_branches |
| 324 | |
| 325 | md_main_oid="$(calc_oid "$(git cat-file -p "refs/heads/main:a.md")")" |
| 326 | md_remote_oid="$(calc_oid "$(git cat-file -p "refs/remotes/origin/main:a.md")")" |
| 327 | md_feature_oid="$(calc_oid "$(git cat-file -p "refs/heads/my-feature:a.md")")" |
| 328 | txt_main_oid="$(calc_oid "$(git cat-file -p "refs/heads/main:a.txt")")" |
| 329 | txt_remote_oid="$(calc_oid "$(git cat-file -p "refs/remotes/origin/main:a.txt")")" |
| 330 | txt_feature_oid="$(calc_oid "$(git cat-file -p "refs/heads/my-feature:a.txt")")" |
| 331 | |
| 332 | git lfs migrate import \ |
| 333 | --include-ref=refs/heads/my-feature \ |
| 334 | --exclude-ref=refs/heads/main |
| 335 | |
| 336 | assert_pointer "refs/heads/my-feature" "a.md" "$md_feature_oid" "31" |
| 337 | assert_pointer "refs/heads/my-feature" "a.txt" "$txt_feature_oid" "30" |
| 338 | |
| 339 | assert_local_object "$md_feature_oid" "31" |
| 340 | refute_local_object "$md_main_oid" "21" |
| 341 | assert_local_object "$txt_feature_oid" "30" |
| 342 | refute_local_object "$txt_main_oid" "20" |
| 343 | refute_local_object "$md_remote_oid" "11" |
| 344 | refute_local_object "$txt_remote_oid" "10" |
| 345 | |
| 346 | main="$(git rev-parse refs/heads/main)" |
| 347 | feature="$(git rev-parse refs/heads/my-feature)" |
| 348 | remote="$(git rev-parse refs/remotes/origin/main)" |
| 349 | |
| 350 | [ -z "$(git cat-file -p "$main:.gitattributes")" ] |
| 351 | [ -z "$(git cat-file -p "$remote:.gitattributes")" ] |
| 352 | feature_attrs="$(git cat-file -p "$feature:.gitattributes")" |
| 353 | |
| 354 | echo "$feature_attrs" | grep -q "*.md filter=lfs diff=lfs merge=lfs" |
| 355 | echo "$feature_attrs" | grep -q "*.txt filter=lfs diff=lfs merge=lfs" |
| 356 | ) |
| 357 | end_test |
| 358 | |
| 359 | begin_test "migrate import (include/exclude ref args)" |
| 360 | ( |
| 361 | set -e |
| 362 | |
| 363 | setup_multiple_remote_branches |
| 364 | |
| 365 | md_main_oid="$(calc_oid "$(git cat-file -p "refs/heads/main:a.md")")" |
| 366 | md_remote_oid="$(calc_oid "$(git cat-file -p "refs/remotes/origin/main:a.md")")" |
| 367 | md_feature_oid="$(calc_oid "$(git cat-file -p "refs/heads/my-feature:a.md")")" |
| 368 | txt_main_oid="$(calc_oid "$(git cat-file -p "refs/heads/main:a.txt")")" |
| 369 | txt_remote_oid="$(calc_oid "$(git cat-file -p "refs/remotes/origin/main:a.txt")")" |
| 370 | txt_feature_oid="$(calc_oid "$(git cat-file -p "refs/heads/my-feature:a.txt")")" |
| 371 | |
| 372 | git lfs migrate import my-feature ^main |
| 373 | |
| 374 | assert_pointer "refs/heads/my-feature" "a.md" "$md_feature_oid" "31" |
| 375 | assert_pointer "refs/heads/my-feature" "a.txt" "$txt_feature_oid" "30" |
| 376 | |
| 377 | assert_local_object "$md_feature_oid" "31" |
| 378 | refute_local_object "$md_main_oid" "21" |
| 379 | assert_local_object "$txt_feature_oid" "30" |
| 380 | refute_local_object "$txt_main_oid" "20" |
| 381 | refute_local_object "$md_remote_oid" "11" |
| 382 | refute_local_object "$txt_remote_oid" "10" |
| 383 | |
| 384 | main="$(git rev-parse refs/heads/main)" |
| 385 | feature="$(git rev-parse refs/heads/my-feature)" |
| 386 | remote="$(git rev-parse refs/remotes/origin/main)" |
| 387 | |
| 388 | [ -z "$(git cat-file -p "$main:.gitattributes")" ] |
| 389 | [ -z "$(git cat-file -p "$remote:.gitattributes")" ] |
| 390 | feature_attrs="$(git cat-file -p "$feature:.gitattributes")" |
| 391 | |
| 392 | echo "$feature_attrs" | grep -q "*.md filter=lfs diff=lfs merge=lfs" |
| 393 | echo "$feature_attrs" | grep -q "*.txt filter=lfs diff=lfs merge=lfs" |
| 394 | ) |
| 395 | end_test |
| 396 | |
| 397 | begin_test "migrate import (include/exclude ref with filter)" |
| 398 | ( |
| 399 | set -e |
| 400 | |
| 401 | setup_multiple_remote_branches |
| 402 | |
| 403 | md_main_oid="$(calc_oid "$(git cat-file -p "refs/heads/main:a.md")")" |
| 404 | md_remote_oid="$(calc_oid "$(git cat-file -p "refs/remotes/origin/main:a.md")")" |
| 405 | md_feature_oid="$(calc_oid "$(git cat-file -p "refs/heads/my-feature:a.md")")" |
| 406 | txt_main_oid="$(calc_oid "$(git cat-file -p "refs/heads/main:a.txt")")" |
| 407 | txt_remote_oid="$(calc_oid "$(git cat-file -p "refs/remotes/origin/main:a.txt")")" |
| 408 | txt_feature_oid="$(calc_oid "$(git cat-file -p "refs/heads/my-feature:a.txt")")" |
| 409 | |
| 410 | git lfs migrate import \ |
| 411 | --include="*.txt" \ |
| 412 | --include-ref=refs/heads/my-feature \ |
| 413 | --exclude-ref=refs/heads/main |
| 414 | |
| 415 | assert_pointer "refs/heads/my-feature" "a.txt" "$txt_feature_oid" "30" |
| 416 | |
| 417 | refute_local_object "$md_feature_oid" "31" |
| 418 | refute_local_object "$md_main_oid" "21" |
| 419 | assert_local_object "$txt_feature_oid" "30" |
| 420 | refute_local_object "$txt_main_oid" "20" |
| 421 | refute_local_object "$md_remote_oid" "11" |
| 422 | refute_local_object "$txt_remote_oid" "10" |
| 423 | |
| 424 | main="$(git rev-parse refs/heads/main)" |
| 425 | feature="$(git rev-parse refs/heads/my-feature)" |
| 426 | remote="$(git rev-parse refs/remotes/origin/main)" |
| 427 | |
| 428 | [ -z "$(git cat-file -p "$main:.gitattributes")" ] |
| 429 | [ -z "$(git cat-file -p "$remote:.gitattributes")" ] |
| 430 | feature_attrs="$(git cat-file -p "$feature:.gitattributes")" |
| 431 | |
| 432 | [ 0 -eq "$(echo "$feature_attrs" | grep -c "*.md filter=lfs diff=lfs merge=lfs")" ] |
| 433 | echo "$feature_attrs" | grep -q "*.txt filter=lfs diff=lfs merge=lfs" |
| 434 | ) |
| 435 | end_test |
| 436 | |
| 437 | begin_test "migrate import (invalid ref)" |
| 438 | ( |
| 439 | set -e |
| 440 | remove_and_create_local_repo "migrate-import-invalid-ref" |
| 441 | git commit --allow-empty -m "initial commit" |
| 442 | |
| 443 | git lfs migrate import --yes jibberish >migrate.log 2>&1 && exit 1 |
| 444 | grep "can't resolve ref" migrate.log |
| 445 | ) |
| 446 | end_test |
| 447 | |
| 448 | begin_test "migrate import (above)" |
| 449 | ( |
| 450 | set -e |
| 451 | setup_single_local_branch_untracked |
| 452 | |
| 453 | md_main_oid="$(calc_oid "$(git cat-file -p "refs/heads/main:a.md")")" |
| 454 | txt_main_oid="$(calc_oid "$(git cat-file -p "refs/heads/main:a.txt")")" |
| 455 | |
| 456 | git lfs migrate import --above 121B |
| 457 | # Ensure that 'a.md', whose size is above our 121 byte threshold |
| 458 | # was converted into a git-lfs pointer by the migration. |
| 459 | assert_local_object "$md_main_oid" "140" |
| 460 | assert_pointer "refs/heads/main" "a.md" "$md_main_oid" "140" |
| 461 | refute_pointer "refs/heads/main" "a.txt" "$txt_main_oid" "120" |
| 462 | refute_local_object "$txt_main_oid" "120" |
| 463 | |
| 464 | # The migration should have identified that *.md files are now |
| 465 | # tracked because it migrated a.md |
| 466 | main_attrs="$(git cat-file -p "$main:.gitattributes")" |
| 467 | |
| 468 | echo "$main_attrs" | grep -q "/a.md filter=lfs diff=lfs merge=lfs" |
| 469 | [ 0 -eq "$(echo "$main_attrs" | grep -c "/a.txt filter=lfs diff=lfs merge=lfs")" ] |
| 470 | git check-attr filter -- a.txt | grep "filter: unspecified" |
| 471 | ) |
| 472 | end_test |
| 473 | |
| 474 | begin_test "migrate import (above without extension)" |
| 475 | ( |
| 476 | set -e |
| 477 | setup_single_local_branch_untracked "just-b" |
| 478 | |
| 479 | b_main_oid="$(calc_oid "$(git cat-file -p "refs/heads/main:just-b")")" |
| 480 | txt_main_oid="$(calc_oid "$(git cat-file -p "refs/heads/main:a.txt")")" |
| 481 | |
| 482 | git lfs migrate import --above 121B |
| 483 | # Ensure that 'b', whose size is above our 121 byte threshold |
| 484 | # was converted into a git-lfs pointer by the migration. |
| 485 | assert_local_object "$b_main_oid" "140" |
| 486 | assert_pointer "refs/heads/main" "just-b" "$b_main_oid" "140" |
| 487 | refute_pointer "refs/heads/main" "a.txt" "$txt_main_oid" "120" |
| 488 | refute_local_object "$txt_main_oid" "120" |
| 489 | |
| 490 | # The migration should have identified that /b is now tracked |
| 491 | # because it migrated it. |
| 492 | main_attrs="$(git cat-file -p "$main:.gitattributes")" |
| 493 | |
| 494 | echo "$main_attrs" | grep -q "/just-b filter=lfs diff=lfs merge=lfs" |
| 495 | [ 0 -eq "$(echo "$main_attrs" | grep -c "/a.txt filter=lfs diff=lfs merge=lfs")" ] |
| 496 | git check-attr filter -- a.txt | grep "filter: unspecified" |
| 497 | ) |
| 498 | end_test |
| 499 | |
| 500 | begin_test "migrate import (above with multiple files)" |
| 501 | ( |
| 502 | set -e |
| 503 | # It is important that this file sort after "a.txt". |
| 504 | setup_single_local_branch_untracked "b.txt" |
| 505 | |
| 506 | a_main_oid="$(calc_oid "$(git cat-file -p "refs/heads/main:a.txt")")" |
| 507 | b_main_oid="$(calc_oid "$(git cat-file -p "refs/heads/main:b.txt")")" |
| 508 | |
| 509 | git lfs migrate import --above 121B |
| 510 | # Ensure that 'a.md', whose size is above our 121 byte threshold |
| 511 | # was converted into a git-lfs pointer by the migration. |
| 512 | assert_local_object "$b_main_oid" "140" |
| 513 | assert_pointer "refs/heads/main" "b.txt" "$b_main_oid" "140" |
| 514 | refute_pointer "refs/heads/main" "a.txt" "$a_main_oid" "120" |
| 515 | refute_local_object "$a_main_oid" "120" |
| 516 | |
| 517 | # The migration should have identified that *.md files are now |
| 518 | # tracked because it migrated a.md |
| 519 | main_attrs="$(git cat-file -p "$main:.gitattributes")" |
| 520 | |
| 521 | echo "$main_attrs" | grep -q "/b.txt filter=lfs diff=lfs merge=lfs" |
| 522 | git check-attr filter -- a.txt | grep "filter: unspecified" |
| 523 | ) |
| 524 | end_test |
| 525 | |
| 526 | begin_test "migrate import (above with include or exclude)" |
| 527 | ( |
| 528 | set -e |
| 529 | setup_single_local_branch_untracked |
| 530 | |
| 531 | md_main_oid="$(calc_oid "$(git cat-file -p "refs/heads/main:a.md")")" |
| 532 | txt_main_oid="$(calc_oid "$(git cat-file -p "refs/heads/main:a.txt")")" |
| 533 | |
| 534 | git lfs migrate import --above 121B --include "*.md" && exit 1 |
| 535 | git lfs migrate import --above 121B --exclude "*.txt" && exit 1 |
| 536 | git lfs migrate import --above 121B --fixup && exit 1 |
| 537 | true |
| 538 | ) |
| 539 | end_test |
| 540 | |
| 541 | begin_test "migrate import (existing .gitattributes)" |
| 542 | ( |
| 543 | set -e |
| 544 | |
| 545 | setup_local_branch_with_gitattrs |
| 546 | |
| 547 | main="$(git rev-parse refs/heads/main)" |
| 548 | |
| 549 | txt_main_oid="$(calc_oid "$(git cat-file -p "$main:a.txt")")" |
| 550 | |
| 551 | git lfs migrate import --yes --include-ref=refs/heads/main --include="*.txt" |
| 552 | |
| 553 | assert_local_object "$txt_main_oid" "120" |
| 554 | |
| 555 | main="$(git rev-parse refs/heads/main)" |
| 556 | prev="$(git rev-parse refs/heads/main^1)" |
| 557 | |
| 558 | diff -u <(git cat-file -p $main:.gitattributes) <(cat <<-EOF |
| 559 | *.txt filter=lfs diff=lfs merge=lfs -text |
| 560 | *.other filter=lfs diff=lfs merge=lfs -text |
| 561 | EOF) |
| 562 | |
| 563 | diff -u <(git cat-file -p $prev:.gitattributes) <(cat <<-EOF |
| 564 | *.txt filter=lfs diff=lfs merge=lfs -text |
| 565 | EOF) |
| 566 | ) |
| 567 | end_test |
| 568 | |
| 569 | begin_test "migrate import (--exclude with existing .gitattributes)" |
| 570 | ( |
| 571 | set -e |
| 572 | |
| 573 | setup_local_branch_with_gitattrs |
| 574 | |
| 575 | main="$(git rev-parse refs/heads/main)" |
| 576 | |
| 577 | txt_main_oid="$(calc_oid "$(git cat-file -p "$main:a.txt")")" |
| 578 | |
| 579 | git lfs migrate import --yes --include-ref=refs/heads/main --include="*.txt" --exclude="*.bin" |
| 580 | |
| 581 | assert_local_object "$txt_main_oid" "120" |
| 582 | |
| 583 | main="$(git rev-parse refs/heads/main)" |
| 584 | prev="$(git rev-parse refs/heads/main^1)" |
| 585 | |
| 586 | diff -u <(git cat-file -p $main:.gitattributes) <(cat <<-EOF |
| 587 | *.txt filter=lfs diff=lfs merge=lfs -text |
| 588 | *.other filter=lfs diff=lfs merge=lfs -text |
| 589 | *.bin !text -filter -merge -diff |
| 590 | EOF) |
| 591 | |
| 592 | diff -u <(git cat-file -p $prev:.gitattributes) <(cat <<-EOF |
| 593 | *.txt filter=lfs diff=lfs merge=lfs -text |
| 594 | *.bin !text -filter -merge -diff |
| 595 | EOF) |
| 596 | ) |
| 597 | end_test |
| 598 | |
| 599 | begin_test "migrate import (existing .gitattributes with different permissions)" |
| 600 | ( |
| 601 | set -e |
| 602 | |
| 603 | # Windows lacks POSIX permissions. |
| 604 | [ "$IS_WINDOWS" -eq 1 ] && exit 0 |
| 605 | |
| 606 | setup_local_branch_with_gitattrs 0755 |
| 607 | |
| 608 | main="$(git rev-parse refs/heads/main)" |
| 609 | |
| 610 | txt_main_oid="$(calc_oid "$(git cat-file -p "$main:a.txt")")" |
| 611 | |
| 612 | [ -x .gitattributes ] |
| 613 | |
| 614 | git lfs migrate import --yes --include-ref=refs/heads/main --include="*.txt" |
| 615 | |
| 616 | [ ! -x .gitattributes ] |
| 617 | |
| 618 | assert_local_object "$txt_main_oid" "120" |
| 619 | |
| 620 | main="$(git rev-parse refs/heads/main)" |
| 621 | prev="$(git rev-parse refs/heads/main^1)" |
| 622 | |
| 623 | diff -u <(git cat-file -p $main:.gitattributes) <(cat <<-EOF |
| 624 | *.txt filter=lfs diff=lfs merge=lfs -text |
| 625 | *.other filter=lfs diff=lfs merge=lfs -text |
| 626 | EOF |
| 627 | ) |
| 628 | |
| 629 | diff -u <(git cat-file -p $prev:.gitattributes) <(cat <<-EOF |
| 630 | *.txt filter=lfs diff=lfs merge=lfs -text |
| 631 | EOF |
| 632 | ) |
| 633 | |
| 634 | attrs_main_sha="$(git show $main:.gitattributes | git hash-object --stdin)" |
| 635 | txt_main_sha="$(git show $main:a.txt | git hash-object --stdin)" |
| 636 | |
| 637 | diff -u <(git ls-tree $main) <(cat <<-EOF |
| 638 | 100644 blob $attrs_main_sha .gitattributes |
| 639 | 100644 blob $txt_main_sha a.txt |
| 640 | EOF |
| 641 | ) |
| 642 | ) |
| 643 | end_test |
| 644 | |
| 645 | begin_test "migrate import (existing .gitattributes symlink)" |
| 646 | ( |
| 647 | set -e |
| 648 | |
| 649 | setup_local_branch_with_gitattrs link |
| 650 | |
| 651 | git lfs migrate import --yes --include-ref=refs/heads/main --include="*.txt" 2>&1 | tee migrate.log |
| 652 | if [ ${PIPESTATUS[0]} -eq 0 ]; then |
| 653 | echo >&2 "fatal: expected git lfs migrate import to fail, didn't" |
| 654 | exit 1 |
| 655 | fi |
| 656 | |
| 657 | grep "expected '.gitattributes' to be a file, got a symbolic link" migrate.log |
| 658 | |
| 659 | main="$(git rev-parse refs/heads/main)" |
| 660 | |
| 661 | attrs_main_sha="$(git show $main:.gitattributes | git hash-object --stdin)" |
| 662 | |
| 663 | diff -u <(git ls-tree $main -- .gitattributes) <(cat <<-EOF |
| 664 | 120000 blob $attrs_main_sha .gitattributes |
| 665 | EOF |
| 666 | ) |
| 667 | ) |
| 668 | end_test |
| 669 | |
| 670 | begin_test "migrate import (identical contents, different permissions)" |
| 671 | ( |
| 672 | set -e |
| 673 | |
| 674 | # Windows lacks POSIX permissions. |
| 675 | [ "$IS_WINDOWS" -eq 1 ] && exit 0 |
| 676 | |
| 677 | setup_multiple_local_branches |
| 678 | git checkout main |
| 679 | |
| 680 | echo "foo" >foo.dat |
| 681 | git add . |
| 682 | git commit -m "add file" |
| 683 | |
| 684 | chmod u+x foo.dat |
| 685 | git add . |
| 686 | git commit -m "make file executable" |
| 687 | |
| 688 | # Verify we have executable permissions. |
| 689 | [ -x foo.dat ] |
| 690 | |
| 691 | git lfs migrate import --everything --include="*.dat" |
| 692 | |
| 693 | # Verify we have executable permissions. |
| 694 | [ -x foo.dat ] |
| 695 | ) |
| 696 | end_test |
| 697 | |
| 698 | begin_test "migrate import (tags with same name as branches)" |
| 699 | ( |
| 700 | set -e |
| 701 | |
| 702 | setup_multiple_local_branches |
| 703 | git checkout main |
| 704 | |
| 705 | contents="hello" |
| 706 | oid=$(calc_oid "$contents") |
| 707 | printf "$contents" >hello.dat |
| 708 | git add . |
| 709 | git commit -m "add file" |
| 710 | |
| 711 | git branch foo |
| 712 | git tag foo |
| 713 | git tag bar |
| 714 | |
| 715 | git lfs migrate import --everything --include="*.dat" |
| 716 | |
| 717 | [ "$(git rev-parse refs/heads/foo)" = "$(git rev-parse refs/tags/foo)" ] |
| 718 | [ "$(git rev-parse refs/heads/foo)" = "$(git rev-parse refs/tags/bar)" ] |
| 719 | |
| 720 | assert_pointer "refs/heads/foo" hello.dat "$oid" 5 |
| 721 | ) |
| 722 | end_test |
| 723 | |
| 724 | begin_test "migrate import (bare repository)" |
| 725 | ( |
| 726 | set -e |
| 727 | |
| 728 | setup_multiple_local_branches |
| 729 | make_bare |
| 730 | |
| 731 | git lfs migrate import \ |
| 732 | --include-ref=main |
| 733 | ) |
| 734 | end_test |
| 735 | |
| 736 | begin_test "migrate import (nested sub-trees, no filter)" |
| 737 | ( |
| 738 | set -e |
| 739 | |
| 740 | setup_single_local_branch_deep_trees |
| 741 | |
| 742 | oid="$(calc_oid "$(git cat-file -p :foo/bar/baz/a.txt)")" |
| 743 | size="$(git cat-file -p :foo/bar/baz/a.txt | wc -c | awk '{ print $1 }')" |
| 744 | |
| 745 | git lfs migrate import --everything |
| 746 | |
| 747 | assert_local_object "$oid" "$size" |
| 748 | ) |
| 749 | end_test |
| 750 | |
| 751 | begin_test "migrate import (prefix include(s))" |
| 752 | ( |
| 753 | set -e |
| 754 | |
| 755 | includes="foo/bar/baz/** foo/**/baz/a.txt *.txt" |
| 756 | for include in $includes; do |
| 757 | setup_single_local_branch_deep_trees |
| 758 | |
| 759 | oid="$(calc_oid "$(git cat-file -p :foo/bar/baz/a.txt)")" |
| 760 | |
| 761 | git lfs migrate import --include="$include" |
| 762 | |
| 763 | assert_local_object "$oid" 120 |
| 764 | |
| 765 | cd .. |
| 766 | done |
| 767 | ) |
| 768 | end_test |
| 769 | |
| 770 | begin_test "migrate import (--everything)" |
| 771 | ( |
| 772 | set -e |
| 773 | |
| 774 | setup_multiple_local_branches |
| 775 | git checkout main |
| 776 | |
| 777 | main_txt_oid="$(calc_oid "$(git cat-file -p :a.txt)")" |
| 778 | main_md_oid="$(calc_oid "$(git cat-file -p :a.md)")" |
| 779 | feature_md_oid="$(calc_oid "$(git cat-file -p my-feature:a.md)")" |
| 780 | main_txt_size="$(git cat-file -p :a.txt | wc -c | awk '{ print $1 }')" |
| 781 | main_md_size="$(git cat-file -p :a.md | wc -c | awk '{ print $1 }')" |
| 782 | feature_md_size="$(git cat-file -p my-feature:a.md | wc -c | awk '{ print $1 }')" |
| 783 | |
| 784 | git lfs migrate import --everything |
| 785 | |
| 786 | assert_pointer "main" "a.txt" "$main_txt_oid" "$main_txt_size" |
| 787 | assert_pointer "main" "a.md" "$main_md_oid" "$main_md_size" |
| 788 | assert_pointer "my-feature" "a.md" "$feature_md_oid" "$feature_md_size" |
| 789 | ) |
| 790 | end_test |
| 791 | |
| 792 | begin_test "migrate import (ambiguous reference)" |
| 793 | ( |
| 794 | set -e |
| 795 | |
| 796 | setup_multiple_local_branches |
| 797 | |
| 798 | # Create an ambiguously named reference sharing the name as the SHA-1 of |
| 799 | # "HEAD". |
| 800 | sha="$(git rev-parse HEAD)" |
| 801 | git tag "$sha" |
| 802 | |
| 803 | git lfs migrate import --everything |
| 804 | ) |
| 805 | end_test |
| 806 | |
| 807 | begin_test "migrate import (--everything with args)" |
| 808 | ( |
| 809 | set -e |
| 810 | |
| 811 | setup_multiple_local_branches |
| 812 | |
| 813 | [ "$(git lfs migrate import --everything main 2>&1)" = \ |
| 814 | "Cannot use --everything with explicit reference arguments" ] |
| 815 | ) |
| 816 | end_test |
| 817 | |
| 818 | begin_test "migrate import (--everything with --include-ref)" |
| 819 | ( |
| 820 | set -e |
| 821 | |
| 822 | setup_multiple_local_branches |
| 823 | |
| 824 | [ "$(git lfs migrate import --everything --include-ref=refs/heads/main 2>&1)" = \ |
| 825 | "Cannot use --everything with --include-ref or --exclude-ref" ] |
| 826 | ) |
| 827 | end_test |
| 828 | |
| 829 | begin_test "migrate import (--everything with --exclude-ref)" |
| 830 | ( |
| 831 | set -e |
| 832 | |
| 833 | setup_multiple_local_branches |
| 834 | |
| 835 | [ "$(git lfs migrate import --everything --exclude-ref=refs/heads/main 2>&1)" = \ |
| 836 | "Cannot use --everything with --include-ref or --exclude-ref" ] |
| 837 | ) |
| 838 | end_test |
| 839 | |
| 840 | begin_test "migrate import (--everything and --include with glob pattern)" |
| 841 | ( |
| 842 | set -e |
| 843 | |
| 844 | setup_multiple_local_branches |
| 845 | |
| 846 | md_main_oid="$(calc_oid "$(git cat-file -p "refs/heads/main:a.md")")" |
| 847 | txt_main_oid="$(calc_oid "$(git cat-file -p "refs/heads/main:a.txt")")" |
| 848 | md_feature_oid="$(calc_oid "$(git cat-file -p "refs/heads/my-feature:a.md")")" |
| 849 | txt_feature_oid="$(calc_oid "$(git cat-file -p "refs/heads/my-feature:a.txt")")" |
| 850 | |
| 851 | original_head="$(git rev-parse HEAD)" |
| 852 | |
| 853 | git lfs migrate import --verbose --everything --include='*.[mM][dD]' --yes 2>&1 | tee migrate.log |
| 854 | grep -q " commit ${original_head}: a\.md" migrate.log |
| 855 | |
| 856 | assert_pointer "refs/heads/main" "a.md" "$md_main_oid" "140" |
| 857 | assert_pointer "refs/heads/my-feature" "a.md" "$md_feature_oid" "30" |
| 858 | |
| 859 | assert_local_object "$md_main_oid" "140" |
| 860 | assert_local_object "$md_feature_oid" "30" |
| 861 | refute_local_object "$txt_main_oid" |
| 862 | refute_local_object "$txt_feature_oid" |
| 863 | ) |
| 864 | end_test |
| 865 | |
| 866 | begin_test "migrate import (--everything with tag pointing to tag)" |
| 867 | ( |
| 868 | set -e |
| 869 | |
| 870 | setup_multiple_local_branches |
| 871 | |
| 872 | md_main_oid="$(calc_oid "$(git cat-file -p "refs/heads/main:a.md")")" |
| 873 | txt_main_oid="$(calc_oid "$(git cat-file -p "refs/heads/main:a.txt")")" |
| 874 | md_feature_oid="$(calc_oid "$(git cat-file -p "refs/heads/my-feature:a.md")")" |
| 875 | txt_feature_oid="$(calc_oid "$(git cat-file -p "refs/heads/my-feature:a.txt")")" |
| 876 | |
| 877 | git tag -a -m abc abc refs/heads/main |
| 878 | git tag -a -m def def refs/tags/abc |
| 879 | |
| 880 | original_head="$(git rev-parse HEAD)" |
| 881 | |
| 882 | git lfs migrate import --verbose --everything --include='*.[mM][dD]' --yes 2>&1 | tee migrate.log |
| 883 | grep -q " commit ${original_head}: a\.md" migrate.log |
| 884 | |
| 885 | assert_pointer "refs/heads/main" "a.md" "$md_main_oid" "140" |
| 886 | assert_pointer "refs/tags/abc" "a.md" "$md_main_oid" "140" |
| 887 | assert_pointer "refs/tags/def" "a.md" "$md_main_oid" "140" |
| 888 | assert_pointer "refs/heads/my-feature" "a.md" "$md_feature_oid" "30" |
| 889 | |
| 890 | git tag --points-at refs/tags/abc | grep -q def |
| 891 | git tag --points-at refs/tags/def | grep -q abc && exit 1 |
| 892 | |
| 893 | assert_local_object "$md_main_oid" "140" |
| 894 | assert_local_object "$md_feature_oid" "30" |
| 895 | refute_local_object "$txt_main_oid" |
| 896 | refute_local_object "$txt_feature_oid" |
| 897 | ) |
| 898 | end_test |
| 899 | |
| 900 | begin_test "migrate import (nested sub-trees and --include with wildcard)" |
| 901 | ( |
| 902 | set -e |
| 903 | |
| 904 | setup_single_local_branch_deep_trees |
| 905 | |
| 906 | oid="$(calc_oid "$(git cat-file -p :foo/bar/baz/a.txt)")" |
| 907 | size="$(git cat-file -p :foo/bar/baz/a.txt | wc -c | awk '{ print $1 }')" |
| 908 | |
| 909 | git lfs migrate import --include="**/*ar/**" |
| 910 | |
| 911 | assert_pointer "refs/heads/main" "foo/bar/baz/a.txt" "$oid" "$size" |
| 912 | assert_local_object "$oid" "$size" |
| 913 | ) |
| 914 | end_test |
| 915 | |
| 916 | begin_test "migrate import (handle copies of files)" |
| 917 | ( |
| 918 | set -e |
| 919 | |
| 920 | setup_single_local_branch_deep_trees |
| 921 | |
| 922 | # add the object from the sub-tree to the root directory |
| 923 | cp foo/bar/baz/a.txt a.txt |
| 924 | git add a.txt |
| 925 | git commit -m "duplicated file" |
| 926 | |
| 927 | oid_root="$(calc_oid "$(git cat-file -p :a.txt)")" |
| 928 | oid_tree="$(calc_oid "$(git cat-file -p :foo/bar/baz/a.txt)")" |
| 929 | size="$(git cat-file -p :foo/bar/baz/a.txt | wc -c | awk '{ print $1 }')" |
| 930 | |
| 931 | # only import objects under "foo" |
| 932 | git lfs migrate import --include="foo/**" |
| 933 | |
| 934 | assert_pointer "refs/heads/main" "foo/bar/baz/a.txt" "$oid_tree" "$size" |
| 935 | assert_local_object "$oid_tree" "$size" |
| 936 | |
| 937 | # "a.txt" is not under "foo" and therefore should not be in LFS |
| 938 | oid_root_after_migration="$(calc_oid "$(git cat-file -p :a.txt)")" |
| 939 | [ "$oid_root" = "$oid_root_after_migration" ] |
| 940 | ) |
| 941 | end_test |
| 942 | |
| 943 | begin_test "migrate import (filter matches files only) (path cache settings)" |
| 944 | ( |
| 945 | set -e |
| 946 | |
| 947 | setup_single_local_branch_same_file_tree_ext |
| 948 | |
| 949 | txt_root_oid="$(calc_oid "$(git cat-file -p :a.txt)")" |
| 950 | txt_foo_oid="$(calc_oid "$(git cat-file -p :foo/a.txt)")" |
| 951 | md_bar_oid="$(calc_oid "$(git cat-file -p :bar.txt/b.md)")" |
| 952 | txt_bar_oid="$(calc_oid "$(git cat-file -p :bar.txt/b.txt)")" |
| 953 | |
| 954 | git lfs migrate import --include="*.txt" |
| 955 | |
| 956 | assert_local_object "$txt_root_oid" "120" |
| 957 | assert_local_object "$txt_foo_oid" "120" |
| 958 | assert_local_object "$txt_bar_oid" "120" |
| 959 | refute_local_object "$md_bar_oid" |
| 960 | |
| 961 | # Also test with various path filter cache settings. |
| 962 | for cache in "none" "1" "2" "unlimited" "not valid"; do |
| 963 | cd .. |
| 964 | rm -rf "$reponame" |
| 965 | setup_single_local_branch_same_file_tree_ext |
| 966 | |
| 967 | txt_root_oid="$(calc_oid "$(git cat-file -p :a.txt)")" |
| 968 | txt_foo_oid="$(calc_oid "$(git cat-file -p :foo/a.txt)")" |
| 969 | md_bar_oid="$(calc_oid "$(git cat-file -p :bar.txt/b.md)")" |
| 970 | txt_bar_oid="$(calc_oid "$(git cat-file -p :bar.txt/b.txt)")" |
| 971 | |
| 972 | git config "lfs.pathFilterCacheSize" "$cache" |
| 973 | |
| 974 | git lfs migrate import --include="*.txt" |
| 975 | |
| 976 | assert_local_object "$txt_root_oid" "120" |
| 977 | assert_local_object "$txt_foo_oid" "120" |
| 978 | assert_local_object "$txt_bar_oid" "120" |
| 979 | refute_local_object "$md_bar_oid" |
| 980 | done |
| 981 | ) |
| 982 | end_test |
| 983 | |
| 984 | begin_test "migrate import (--object-map)" |
| 985 | ( |
| 986 | set -e |
| 987 | |
| 988 | setup_multiple_local_branches |
| 989 | |
| 990 | output_dir="$GIT_LFS_TEST_DIR/import-object-map-$(lfstest-genrandom --base64url 32)" |
| 991 | mkdir -p "$output_dir" |
| 992 | |
| 993 | git log --all --pretty='format:%H' > "${output_dir}/old_sha.txt" |
| 994 | git lfs migrate import --everything --object-map "${output_dir}/object-map.txt" |
| 995 | git log --all --pretty='format:%H' > "${output_dir}/new_sha.txt" |
| 996 | paste -d',' "${output_dir}/old_sha.txt" "${output_dir}/new_sha.txt" > "${output_dir}/expected-map.txt" |
| 997 | |
| 998 | diff -u <(sort "${output_dir}/expected-map.txt") <(sort "${output_dir}/object-map.txt") |
| 999 | ) |
| 1000 | end_test |
| 1001 | |
| 1002 | begin_test "migrate import (--include with space)" |
| 1003 | ( |
| 1004 | set -e |
| 1005 | |
| 1006 | setup_local_branch_with_space |
| 1007 | |
| 1008 | oid="$(calc_oid "$(git cat-file -p :"a file.txt")")" |
| 1009 | |
| 1010 | git lfs migrate import --include "a file.txt" |
| 1011 | |
| 1012 | assert_pointer "refs/heads/main" "a file.txt" "$oid" 50 |
| 1013 | cat .gitattributes |
| 1014 | if [ 1 -ne "$(grep -c "a\[\[:space:\]\]file.txt" .gitattributes)" ]; then |
| 1015 | echo >&2 "fatal: expected \"a[[:space:]]file.txt\" to appear in .gitattributes" |
| 1016 | echo >&2 "fatal: got" |
| 1017 | sed -e 's/^/ /g' < .gitattributes >&2 |
| 1018 | exit 1 |
| 1019 | fi |
| 1020 | ) |
| 1021 | end_test |
| 1022 | |
| 1023 | begin_test "migrate import (handle symbolic link)" |
| 1024 | ( |
| 1025 | set -e |
| 1026 | |
| 1027 | setup_local_branch_with_symlink |
| 1028 | |
| 1029 | txt_oid="$(calc_oid "$(git cat-file -p :a.txt)")" |
| 1030 | link_oid="$(calc_oid "$(git cat-file -p :link.txt)")" |
| 1031 | |
| 1032 | git lfs migrate import --include="*.txt" |
| 1033 | |
| 1034 | assert_pointer "refs/heads/main" "a.txt" "$txt_oid" "120" |
| 1035 | |
| 1036 | assert_local_object "$txt_oid" "120" |
| 1037 | # "link.txt" is a symbolic link so it should be not in LFS |
| 1038 | refute_local_object "$link_oid" "5" |
| 1039 | ) |
| 1040 | end_test |
| 1041 | |
| 1042 | begin_test "migrate import (commit --allow-empty)" |
| 1043 | ( |
| 1044 | set -e |
| 1045 | |
| 1046 | reponame="migrate---allow-empty" |
| 1047 | git init "$reponame" |
| 1048 | cd "$reponame" |
| 1049 | |
| 1050 | git commit --allow-empty -m "initial commit" |
| 1051 | |
| 1052 | original_head="$(git rev-parse HEAD)" |
| 1053 | git lfs migrate import --everything |
| 1054 | migrated_head="$(git rev-parse HEAD)" |
| 1055 | |
| 1056 | assert_ref_unmoved "HEAD" "$original_head" "$migrated_head" |
| 1057 | ) |
| 1058 | end_test |
| 1059 | |
| 1060 | begin_test "migrate import (multiple remotes)" |
| 1061 | ( |
| 1062 | set -e |
| 1063 | |
| 1064 | setup_multiple_remotes |
| 1065 | |
| 1066 | original_main="$(git rev-parse main)" |
| 1067 | |
| 1068 | git lfs migrate import |
| 1069 | |
| 1070 | migrated_main="$(git rev-parse main)" |
| 1071 | |
| 1072 | assert_ref_unmoved "main" "$original_main" "$migrated_main" |
| 1073 | ) |
| 1074 | end_test |
| 1075 | |
| 1076 | begin_test "migrate import (dirty copy, default negative answer)" |
| 1077 | ( |
| 1078 | set -e |
| 1079 | |
| 1080 | setup_local_branch_with_dirty_copy |
| 1081 | |
| 1082 | original_main="$(git rev-parse main)" |
| 1083 | |
| 1084 | echo | git lfs migrate import --everything 2>&1 | tee migrate.log |
| 1085 | grep "working copy must not be dirty" migrate.log |
| 1086 | |
| 1087 | migrated_main="$(git rev-parse main)" |
| 1088 | |
| 1089 | assert_ref_unmoved "main" "$original_main" "$migrated_main" |
| 1090 | ) |
| 1091 | end_test |
| 1092 | |
| 1093 | begin_test "migrate import (dirty copy, negative answer)" |
| 1094 | ( |
| 1095 | set -e |
| 1096 | |
| 1097 | setup_local_branch_with_dirty_copy |
| 1098 | |
| 1099 | original_main="$(git rev-parse main)" |
| 1100 | |
| 1101 | echo "n" | git lfs migrate import --everything 2>&1 | tee migrate.log |
| 1102 | grep "working copy must not be dirty" migrate.log |
| 1103 | |
| 1104 | migrated_main="$(git rev-parse main)" |
| 1105 | |
| 1106 | assert_ref_unmoved "main" "$original_main" "$migrated_main" |
| 1107 | ) |
| 1108 | end_test |
| 1109 | |
| 1110 | begin_test "migrate import (dirty copy, unknown then negative answer)" |
| 1111 | ( |
| 1112 | set -e |
| 1113 | |
| 1114 | setup_local_branch_with_dirty_copy |
| 1115 | |
| 1116 | original_main="$(git rev-parse main)" |
| 1117 | |
| 1118 | echo "x\nn" | git lfs migrate import --everything 2>&1 | tee migrate.log |
| 1119 | |
| 1120 | cat migrate.log |
| 1121 | |
| 1122 | [ "2" -eq "$(grep -o "override changes in your working copy" migrate.log \ |
| 1123 | | wc -l | awk '{ print $1 }')" ] |
| 1124 | grep "working copy must not be dirty" migrate.log |
| 1125 | |
| 1126 | migrated_main="$(git rev-parse main)" |
| 1127 | |
| 1128 | assert_ref_unmoved "main" "$original_main" "$migrated_main" |
| 1129 | ) |
| 1130 | end_test |
| 1131 | |
| 1132 | begin_test "migrate import (dirty copy, positive answer)" |
| 1133 | ( |
| 1134 | set -e |
| 1135 | |
| 1136 | setup_local_branch_with_dirty_copy |
| 1137 | |
| 1138 | oid="$(calc_oid "$(git cat-file -p :a.txt)")" |
| 1139 | |
| 1140 | echo "y" | git lfs migrate import --everything 2>&1 | tee migrate.log |
| 1141 | grep "changes in your working copy will be overridden ..." \ |
| 1142 | migrate.log |
| 1143 | |
| 1144 | assert_pointer "refs/heads/main" "a.txt" "$oid" "5" |
| 1145 | assert_local_object "$oid" "5" |
| 1146 | ) |
| 1147 | end_test |
| 1148 | |
| 1149 | begin_test "migrate import (non-standard refs)" |
| 1150 | ( |
| 1151 | set -e |
| 1152 | |
| 1153 | setup_multiple_local_branches_non_standard |
| 1154 | |
| 1155 | md_oid="$(calc_oid "$(git cat-file -p :a.md)")" |
| 1156 | txt_oid="$(calc_oid "$(git cat-file -p :a.txt)")" |
| 1157 | md_feature_oid="$(calc_oid "$(git cat-file -p my-feature:a.md)")" |
| 1158 | |
| 1159 | git lfs migrate import --everything |
| 1160 | |
| 1161 | assert_pointer "refs/heads/main" "a.md" "$md_oid" "140" |
| 1162 | assert_pointer "refs/heads/main" "a.txt" "$txt_oid" "120" |
| 1163 | assert_pointer "refs/pull/1/base" "a.md" "$md_oid" "140" |
| 1164 | assert_pointer "refs/pull/1/base" "a.txt" "$txt_oid" "120" |
| 1165 | |
| 1166 | assert_pointer "refs/heads/my-feature" "a.txt" "$txt_oid" "120" |
| 1167 | assert_pointer "refs/pull/1/head" "a.txt" "$txt_oid" "120" |
| 1168 | |
| 1169 | assert_local_object "$md_oid" "140" |
| 1170 | assert_local_object "$txt_oid" "120" |
| 1171 | assert_local_object "$md_feature_oid" "30" |
| 1172 | ) |
| 1173 | end_test |
| 1174 | |
| 1175 | begin_test "migrate import (copied file)" |
| 1176 | ( |
| 1177 | set -e |
| 1178 | |
| 1179 | setup_local_branch_with_copied_file |
| 1180 | |
| 1181 | git lfs migrate import --above=1b |
| 1182 | |
| 1183 | # Expect attributes for "/dir/a" and "/a" |
| 1184 | if ! grep -q "^/dir/a.txt" ./.gitattributes || ! grep -q "^/a.txt" ./.gitattributes; then |
| 1185 | exit 1 |
| 1186 | fi |
| 1187 | ) |
| 1188 | end_test |
| 1189 | |
| 1190 | begin_test "migrate import (copied file with only a single path)" |
| 1191 | ( |
| 1192 | set -e |
| 1193 | |
| 1194 | setup_local_branch_with_copied_file |
| 1195 | |
| 1196 | oid="$(calc_oid "$(git cat-file -p :a.txt)")" |
| 1197 | |
| 1198 | # Prevent MSYS from rewriting /a.txt into a Windows path. |
| 1199 | MSYS_NO_PATHCONV=1 git lfs migrate import --include="/a.txt" --everything |
| 1200 | |
| 1201 | # Expect attribute for only "/a.txt". |
| 1202 | if grep -q "^/dir/a.txt" ./.gitattributes || ! grep -q "^/a.txt" ./.gitattributes; then |
| 1203 | exit 1 |
| 1204 | fi |
| 1205 | refute_pointer "refs/heads/main" "dir/a.txt" "$oid" 5 |
| 1206 | ) |
| 1207 | end_test |
| 1208 | |
| 1209 | begin_test "migrate import (filename special characters)" |
| 1210 | ( |
| 1211 | set -e |
| 1212 | setup_local_branch_with_special_character_files |
| 1213 | git lfs migrate import --above=1b |
| 1214 | # Windows does not allow creation of files with '*', so expect 2 files, not 3 |
| 1215 | if [ "$IS_WINDOWS" -eq "1" ] ; then |
| 1216 | [ 2 -eq "$(git check-attr filter -- *.bin | grep -c "filter: lfs")" ] |
| 1217 | else |
| 1218 | [ 3 -eq "$(git check-attr filter -- *.bin | grep -c "filter: lfs")" ] |
| 1219 | fi |
| 1220 | ) |
| 1221 | end_test |