3 . "$(dirname "$0")/fixtures/migrate.sh"
4 . "$(dirname "$0")/testlib.sh"
6 begin_test "migrate import (default branch)"
10 setup_multiple_local_branches
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)")"
16 git lfs migrate import
18 assert_pointer "refs/heads/master" "a.md" "$md_oid" "140"
19 assert_pointer "refs/heads/master" "a.txt" "$txt_oid" "120"
21 assert_local_object "$md_oid" "140"
22 assert_local_object "$txt_oid" "120"
23 refute_local_object "$md_feature_oid" "30"
25 master="$(git rev-parse refs/heads/master)"
26 feature="$(git rev-parse refs/heads/my-feature)"
28 master_attrs="$(git cat-file -p "$master:.gitattributes")"
29 [ ! $(git cat-file -p "$feature:.gitattributes") ]
31 echo "$master_attrs" | grep -q "*.md filter=lfs diff=lfs merge=lfs"
32 echo "$master_attrs" | grep -q "*.txt filter=lfs diff=lfs merge=lfs"
36 begin_test "migrate import (bare repository)"
40 setup_multiple_remote_branches
42 git lfs migrate import --everything
46 begin_test "migrate import (given branch)"
50 setup_multiple_local_branches
52 md_oid="$(calc_oid "$(git cat-file -p :a.md)")"
53 txt_oid="$(calc_oid "$(git cat-file -p :a.txt)")"
54 md_feature_oid="$(calc_oid "$(git cat-file -p my-feature:a.md)")"
56 git lfs migrate import my-feature
58 assert_pointer "refs/heads/my-feature" "a.md" "$md_feature_oid" "30"
59 assert_pointer "refs/heads/my-feature" "a.txt" "$txt_oid" "120"
60 assert_pointer "refs/heads/master" "a.md" "$md_oid" "140"
61 assert_pointer "refs/heads/master" "a.txt" "$txt_oid" "120"
63 assert_local_object "$md_oid" "140"
64 assert_local_object "$md_feature_oid" "30"
65 assert_local_object "$txt_oid" "120"
67 master="$(git rev-parse refs/heads/master)"
68 feature="$(git rev-parse refs/heads/my-feature)"
70 master_attrs="$(git cat-file -p "$master:.gitattributes")"
71 feature_attrs="$(git cat-file -p "$feature:.gitattributes")"
73 echo "$master_attrs" | grep -q "*.md filter=lfs diff=lfs merge=lfs"
74 echo "$master_attrs" | grep -q "*.txt filter=lfs diff=lfs merge=lfs"
75 echo "$feature_attrs" | grep -q "*.md filter=lfs diff=lfs merge=lfs"
76 echo "$feature_attrs" | grep -q "*.txt filter=lfs diff=lfs merge=lfs"
80 begin_test "migrate import (default branch with filter)"
84 setup_multiple_local_branches
86 md_oid="$(calc_oid "$(git cat-file -p :a.md)")"
87 txt_oid="$(calc_oid "$(git cat-file -p :a.txt)")"
88 md_feature_oid="$(calc_oid "$(git cat-file -p my-feature:a.md)")"
90 git lfs migrate import --include "*.md"
92 assert_pointer "refs/heads/master" "a.md" "$md_oid" "140"
94 assert_local_object "$md_oid" "140"
95 refute_local_object "$txt_oid" "120"
96 refute_local_object "$md_feature_oid" "30"
98 master="$(git rev-parse refs/heads/master)"
99 feature="$(git rev-parse refs/heads/my-feature)"
101 master_attrs="$(git cat-file -p "$master:.gitattributes")"
102 [ ! $(git cat-file -p "$feature:.gitattributes") ]
104 echo "$master_attrs" | grep -q "*.md filter=lfs diff=lfs merge=lfs"
105 echo "$master_attrs" | grep -vq "*.txt filter=lfs diff=lfs merge=lfs"
109 begin_test "migrate import (given branch with filter)"
113 setup_multiple_local_branches
115 md_oid="$(calc_oid "$(git cat-file -p :a.md)")"
116 txt_oid="$(calc_oid "$(git cat-file -p :a.txt)")"
117 md_feature_oid="$(calc_oid "$(git cat-file -p my-feature:a.md)")"
119 git lfs migrate import --include "*.md" my-feature
121 assert_pointer "refs/heads/my-feature" "a.md" "$md_feature_oid" "30"
122 assert_pointer "refs/heads/my-feature~1" "a.md" "$md_oid" "140"
124 assert_local_object "$md_oid" "140"
125 assert_local_object "$md_feature_oid" "30"
126 refute_local_object "$txt_oid" "120"
128 master="$(git rev-parse refs/heads/master)"
129 feature="$(git rev-parse refs/heads/my-feature)"
131 master_attrs="$(git cat-file -p "$master:.gitattributes")"
132 feature_attrs="$(git cat-file -p "$feature:.gitattributes")"
134 echo "$master_attrs" | grep -q "*.md filter=lfs diff=lfs merge=lfs"
135 echo "$master_attrs" | grep -vq "*.txt filter=lfs diff=lfs merge=lfs"
136 echo "$feature_attrs" | grep -q "*.md filter=lfs diff=lfs merge=lfs"
137 echo "$feature_attrs" | grep -vq "*.txt filter=lfs diff=lfs merge=lfs"
141 begin_test "migrate import (default branch, exclude remote refs)"
145 setup_single_remote_branch
147 md_remote_oid="$(calc_oid "$(git cat-file -p "refs/remotes/origin/master:a.md")")"
148 txt_remote_oid="$(calc_oid "$(git cat-file -p "refs/remotes/origin/master:a.txt")")"
149 md_oid="$(calc_oid "$(git cat-file -p "refs/heads/master:a.md")")"
150 txt_oid="$(calc_oid "$(git cat-file -p "refs/heads/master:a.txt")")"
152 git lfs migrate import
154 assert_pointer "refs/heads/master" "a.md" "$md_oid" "50"
155 assert_pointer "refs/heads/master" "a.txt" "$txt_oid" "30"
157 assert_local_object "$md_oid" "50"
158 assert_local_object "$txt_oid" "30"
159 refute_local_object "$md_remote_oid" "140"
160 refute_local_object "$txt_remote_oid" "120"
162 master="$(git rev-parse refs/heads/master)"
163 remote="$(git rev-parse refs/remotes/origin/master)"
165 master_attrs="$(git cat-file -p "$master:.gitattributes")"
166 [ ! $(git cat-file -p "$remote:.gitattributes") ]
168 echo "$master_attrs" | grep -q "*.md filter=lfs diff=lfs merge=lfs"
169 echo "$master_attrs" | grep -vq "*.txt filter=lfs diff=lfs merge=lfs"
173 begin_test "migrate import (given branch, exclude remote refs)"
177 setup_multiple_remote_branches
179 md_master_oid="$(calc_oid "$(git cat-file -p "refs/heads/master:a.md")")"
180 md_remote_oid="$(calc_oid "$(git cat-file -p "refs/remotes/origin/master:a.md")")"
181 md_feature_oid="$(calc_oid "$(git cat-file -p "refs/heads/my-feature:a.md")")"
182 txt_master_oid="$(calc_oid "$(git cat-file -p "refs/heads/master:a.txt")")"
183 txt_remote_oid="$(calc_oid "$(git cat-file -p "refs/remotes/origin/master:a.txt")")"
184 txt_feature_oid="$(calc_oid "$(git cat-file -p "refs/heads/my-feature:a.txt")")"
186 git lfs migrate import my-feature
188 assert_pointer "refs/heads/master" "a.md" "$md_master_oid" "21"
189 assert_pointer "refs/heads/my-feature" "a.md" "$md_feature_oid" "31"
190 assert_pointer "refs/heads/master" "a.txt" "$txt_master_oid" "20"
191 assert_pointer "refs/heads/my-feature" "a.txt" "$txt_feature_oid" "30"
193 assert_local_object "$md_feature_oid" "31"
194 assert_local_object "$md_master_oid" "21"
195 assert_local_object "$txt_feature_oid" "30"
196 assert_local_object "$txt_master_oid" "20"
197 refute_local_object "$md_remote_oid" "11"
198 refute_local_object "$txt_remote_oid" "10"
200 master="$(git rev-parse refs/heads/master)"
201 feature="$(git rev-parse refs/heads/my-feature)"
202 remote="$(git rev-parse refs/remotes/origin/master)"
204 master_attrs="$(git cat-file -p "$master:.gitattributes")"
205 [ ! $(git cat-file -p "$remote:.gitattributes") ]
206 feature_attrs="$(git cat-file -p "$feature:.gitattributes")"
208 echo "$master_attrs" | grep -q "*.md filter=lfs diff=lfs merge=lfs"
209 echo "$master_attrs" | grep -q "*.txt filter=lfs diff=lfs merge=lfs"
210 echo "$feature_attrs" | grep -q "*.md filter=lfs diff=lfs merge=lfs"
211 echo "$feature_attrs" | grep -vq "*.txt filter=lfs diff=lfs merge=lfs"
215 begin_test "migrate import (given ref, --skip-fetch)"
219 setup_single_remote_branch
221 md_master_oid="$(calc_oid "$(git cat-file -p "refs/heads/master:a.md")")"
222 md_remote_oid="$(calc_oid "$(git cat-file -p "refs/remotes/origin/master:a.md")")"
223 txt_master_oid="$(calc_oid "$(git cat-file -p "refs/heads/master:a.txt")")"
224 txt_remote_oid="$(calc_oid "$(git cat-file -p "refs/remotes/origin/master:a.txt")")"
226 git tag pseudo-remote "$(git rev-parse refs/remotes/origin/master)"
227 # Remove the refs/remotes/origin/master ref, and instruct 'git lfs migrate' to
229 git update-ref -d refs/remotes/origin/master
231 git lfs migrate import --skip-fetch
233 assert_pointer "refs/heads/master" "a.md" "$md_master_oid" "50"
234 assert_pointer "pseudo-remote" "a.md" "$md_remote_oid" "140"
235 assert_pointer "refs/heads/master" "a.txt" "$txt_master_oid" "30"
236 assert_pointer "pseudo-remote" "a.txt" "$txt_remote_oid" "120"
238 assert_local_object "$md_master_oid" "50"
239 assert_local_object "$txt_master_oid" "30"
240 assert_local_object "$md_remote_oid" "140"
241 assert_local_object "$txt_remote_oid" "120"
243 master="$(git rev-parse refs/heads/master)"
244 remote="$(git rev-parse pseudo-remote)"
246 master_attrs="$(git cat-file -p "$master:.gitattributes")"
247 remote_attrs="$(git cat-file -p "$remote:.gitattributes")"
249 echo "$master_attrs" | grep -q "*.md filter=lfs diff=lfs merge=lfs"
250 echo "$master_attrs" | grep -q "*.txt filter=lfs diff=lfs merge=lfs"
251 echo "$remote_attrs" | grep -q "*.md filter=lfs diff=lfs merge=lfs"
252 echo "$remote_attrs" | grep -q "*.txt filter=lfs diff=lfs merge=lfs"
256 begin_test "migrate import (un-annotated tags)"
260 setup_single_local_branch_with_tags
262 txt_master_oid="$(calc_oid "$(git cat-file -p "refs/heads/master:a.txt")")"
264 git lfs migrate import --everything
266 assert_pointer "refs/heads/master" "a.txt" "$txt_master_oid" "2"
267 assert_local_object "$txt_master_oid" "2"
269 git tag --points-at "$(git rev-parse HEAD)" | grep -q "v1.0.0"
273 begin_test "migrate import (annotated tags)"
277 setup_single_local_branch_with_annotated_tags
279 txt_master_oid="$(calc_oid "$(git cat-file -p "refs/heads/master:a.txt")")"
281 git lfs migrate import --everything
283 assert_pointer "refs/heads/master" "a.txt" "$txt_master_oid" "2"
284 assert_local_object "$txt_master_oid" "2"
286 git tag --points-at "$(git rev-parse HEAD)" | grep -q "v1.0.0"
290 begin_test "migrate import (include/exclude ref)"
294 setup_multiple_remote_branches
296 md_master_oid="$(calc_oid "$(git cat-file -p "refs/heads/master:a.md")")"
297 md_remote_oid="$(calc_oid "$(git cat-file -p "refs/remotes/origin/master:a.md")")"
298 md_feature_oid="$(calc_oid "$(git cat-file -p "refs/heads/my-feature:a.md")")"
299 txt_master_oid="$(calc_oid "$(git cat-file -p "refs/heads/master:a.txt")")"
300 txt_remote_oid="$(calc_oid "$(git cat-file -p "refs/remotes/origin/master:a.txt")")"
301 txt_feature_oid="$(calc_oid "$(git cat-file -p "refs/heads/my-feature:a.txt")")"
303 git lfs migrate import \
304 --include-ref=refs/heads/my-feature \
305 --exclude-ref=refs/heads/master
307 assert_pointer "refs/heads/my-feature" "a.md" "$md_feature_oid" "31"
308 assert_pointer "refs/heads/my-feature" "a.txt" "$txt_feature_oid" "30"
310 assert_local_object "$md_feature_oid" "31"
311 refute_local_object "$md_master_oid" "21"
312 assert_local_object "$txt_feature_oid" "30"
313 refute_local_object "$txt_master_oid" "20"
314 refute_local_object "$md_remote_oid" "11"
315 refute_local_object "$txt_remote_oid" "10"
317 master="$(git rev-parse refs/heads/master)"
318 feature="$(git rev-parse refs/heads/my-feature)"
319 remote="$(git rev-parse refs/remotes/origin/master)"
321 [ ! $(git cat-file -p "$master:.gitattributes") ]
322 [ ! $(git cat-file -p "$remote:.gitattributes") ]
323 feature_attrs="$(git cat-file -p "$feature:.gitattributes")"
325 echo "$feature_attrs" | grep -q "*.md filter=lfs diff=lfs merge=lfs"
326 echo "$feature_attrs" | grep -q "*.txt filter=lfs diff=lfs merge=lfs"
330 begin_test "migrate import (include/exclude ref args)"
334 setup_multiple_remote_branches
336 md_master_oid="$(calc_oid "$(git cat-file -p "refs/heads/master:a.md")")"
337 md_remote_oid="$(calc_oid "$(git cat-file -p "refs/remotes/origin/master:a.md")")"
338 md_feature_oid="$(calc_oid "$(git cat-file -p "refs/heads/my-feature:a.md")")"
339 txt_master_oid="$(calc_oid "$(git cat-file -p "refs/heads/master:a.txt")")"
340 txt_remote_oid="$(calc_oid "$(git cat-file -p "refs/remotes/origin/master:a.txt")")"
341 txt_feature_oid="$(calc_oid "$(git cat-file -p "refs/heads/my-feature:a.txt")")"
343 git lfs migrate import my-feature ^master
345 assert_pointer "refs/heads/my-feature" "a.md" "$md_feature_oid" "31"
346 assert_pointer "refs/heads/my-feature" "a.txt" "$txt_feature_oid" "30"
348 assert_local_object "$md_feature_oid" "31"
349 refute_local_object "$md_master_oid" "21"
350 assert_local_object "$txt_feature_oid" "30"
351 refute_local_object "$txt_master_oid" "20"
352 refute_local_object "$md_remote_oid" "11"
353 refute_local_object "$txt_remote_oid" "10"
355 master="$(git rev-parse refs/heads/master)"
356 feature="$(git rev-parse refs/heads/my-feature)"
357 remote="$(git rev-parse refs/remotes/origin/master)"
359 [ ! $(git cat-file -p "$master:.gitattributes") ]
360 [ ! $(git cat-file -p "$remote:.gitattributes") ]
361 feature_attrs="$(git cat-file -p "$feature:.gitattributes")"
363 echo "$feature_attrs" | grep -q "*.md filter=lfs diff=lfs merge=lfs"
364 echo "$feature_attrs" | grep -q "*.txt filter=lfs diff=lfs merge=lfs"
368 begin_test "migrate import (include/exclude ref with filter)"
372 setup_multiple_remote_branches
374 md_master_oid="$(calc_oid "$(git cat-file -p "refs/heads/master:a.md")")"
375 md_remote_oid="$(calc_oid "$(git cat-file -p "refs/remotes/origin/master:a.md")")"
376 md_feature_oid="$(calc_oid "$(git cat-file -p "refs/heads/my-feature:a.md")")"
377 txt_master_oid="$(calc_oid "$(git cat-file -p "refs/heads/master:a.txt")")"
378 txt_remote_oid="$(calc_oid "$(git cat-file -p "refs/remotes/origin/master:a.txt")")"
379 txt_feature_oid="$(calc_oid "$(git cat-file -p "refs/heads/my-feature:a.txt")")"
381 git lfs migrate import \
383 --include-ref=refs/heads/my-feature \
384 --exclude-ref=refs/heads/master
386 assert_pointer "refs/heads/my-feature" "a.txt" "$txt_feature_oid" "30"
388 refute_local_object "$md_feature_oid" "31"
389 refute_local_object "$md_master_oid" "21"
390 assert_local_object "$txt_feature_oid" "30"
391 refute_local_object "$txt_master_oid" "20"
392 refute_local_object "$md_remote_oid" "11"
393 refute_local_object "$txt_remote_oid" "10"
395 master="$(git rev-parse refs/heads/master)"
396 feature="$(git rev-parse refs/heads/my-feature)"
397 remote="$(git rev-parse refs/remotes/origin/master)"
399 [ ! $(git cat-file -p "$master:.gitattributes") ]
400 [ ! $(git cat-file -p "$remote:.gitattributes") ]
401 feature_attrs="$(git cat-file -p "$feature:.gitattributes")"
403 echo "$feature_attrs" | grep -vq "*.md filter=lfs diff=lfs merge=lfs"
404 echo "$feature_attrs" | grep -q "*.txt filter=lfs diff=lfs merge=lfs"
408 begin_test "migrate import (existing .gitattributes)"
412 setup_local_branch_with_gitattrs
416 master="$(git rev-parse refs/heads/master)"
418 txt_master_oid="$(calc_oid "$(git cat-file -p "$master:a.txt")")"
420 git lfs migrate import --yes --include-ref=refs/heads/master --include="*.txt"
422 assert_local_object "$txt_master_oid" "120"
424 master="$(git rev-parse refs/heads/master)"
425 prev="$(git rev-parse refs/heads/master^1)"
427 diff -u <(git cat-file -p $master:.gitattributes) <(cat <<-EOF
428 *.txt filter=lfs diff=lfs merge=lfs -text
429 *.other filter=lfs diff=lfs merge=lfs -text
432 diff -u <(git cat-file -p $prev:.gitattributes) <(cat <<-EOF
433 *.txt filter=lfs diff=lfs merge=lfs -text
438 begin_test "migrate import (bare repository)"
442 setup_multiple_local_branches
445 git lfs migrate import \
450 begin_test "migrate import (nested sub-trees, no filter)"
454 setup_single_local_branch_deep_trees
456 oid="$(calc_oid "$(git cat-file -p :foo/bar/baz/a.txt)")"
457 size="$(git cat-file -p :foo/bar/baz/a.txt | wc -c | awk '{ print $1 }')"
459 git lfs migrate import --everything
461 assert_local_object "$oid" "$size"
465 begin_test "migrate import (prefix include(s))"
469 includes="foo/bar/baz foo/**/baz/a.txt *.txt"
470 for include in $includes; do
471 setup_single_local_branch_deep_trees
473 oid="$(calc_oid "$(git cat-file -p :foo/bar/baz/a.txt)")"
475 git lfs migrate import --include="$include"
477 assert_local_object "$oid" 120
484 begin_test "migrate import (--everything)"
488 setup_multiple_local_branches
491 master_txt_oid="$(calc_oid "$(git cat-file -p :a.txt)")"
492 master_md_oid="$(calc_oid "$(git cat-file -p :a.md)")"
493 feature_md_oid="$(calc_oid "$(git cat-file -p my-feature:a.md)")"
494 master_txt_size="$(git cat-file -p :a.txt | wc -c | awk '{ print $1 }')"
495 master_md_size="$(git cat-file -p :a.md | wc -c | awk '{ print $1 }')"
496 feature_md_size="$(git cat-file -p my-feature:a.md | wc -c | awk '{ print $1 }')"
498 git lfs migrate import --everything
500 assert_pointer "master" "a.txt" "$master_txt_oid" "$master_txt_size"
501 assert_pointer "master" "a.md" "$master_md_oid" "$master_md_size"
502 assert_pointer "my-feature" "a.md" "$feature_md_oid" "$feature_md_size"
506 begin_test "migrate import (ambiguous reference)"
510 setup_multiple_local_branches
512 # Create an ambiguously named reference sharing the name as the SHA-1 of
514 sha="$(git rev-parse HEAD)"
517 git lfs migrate import --everything
521 begin_test "migrate import (--everything with args)"
525 setup_multiple_local_branches
527 [ "$(git lfs migrate import --everything master 2>&1)" = \
528 "fatal: cannot use --everything with explicit reference arguments" ]
532 begin_test "migrate import (--everything with --include-ref)"
536 setup_multiple_local_branches
538 [ "$(git lfs migrate import --everything --include-ref=refs/heads/master 2>&1)" = \
539 "fatal: cannot use --everything with --include-ref or --exclude-ref" ]
543 begin_test "migrate import (--everything with --exclude-ref)"
547 setup_multiple_local_branches
549 [ "$(git lfs migrate import --everything --exclude-ref=refs/heads/master 2>&1)" = \
550 "fatal: cannot use --everything with --include-ref or --exclude-ref" ]
554 begin_test "migrate import (--everything and --include with glob pattern)"
558 setup_multiple_local_branches
560 md_master_oid="$(calc_oid "$(git cat-file -p "refs/heads/master:a.md")")"
561 txt_master_oid="$(calc_oid "$(git cat-file -p "refs/heads/master:a.txt")")"
562 md_feature_oid="$(calc_oid "$(git cat-file -p "refs/heads/my-feature:a.md")")"
563 txt_feature_oid="$(calc_oid "$(git cat-file -p "refs/heads/my-feature:a.txt")")"
565 git lfs migrate import --verbose --everything --include='*.[mM][dD]'
567 assert_pointer "refs/heads/master" "a.md" "$md_master_oid" "140"
568 assert_pointer "refs/heads/my-feature" "a.md" "$md_feature_oid" "30"
570 assert_local_object "$md_master_oid" "140"
571 assert_local_object "$md_feature_oid" "30"
572 refute_local_object "$txt_master_oid"
573 refute_local_object "$txt_feature_oid"
577 begin_test "migrate import (nested sub-trees and --include with wildcard)"
581 setup_single_local_branch_deep_trees
583 oid="$(calc_oid "$(git cat-file -p :foo/bar/baz/a.txt)")"
584 size="$(git cat-file -p :foo/bar/baz/a.txt | wc -c | awk '{ print $1 }')"
586 git lfs migrate import --include="**/*ar/**"
588 assert_pointer "refs/heads/master" "foo/bar/baz/a.txt" "$oid" "$size"
589 assert_local_object "$oid" "$size"
593 begin_test "migrate import (handle copies of files)"
597 setup_single_local_branch_deep_trees
599 # add the object from the sub-tree to the root directory
600 cp foo/bar/baz/a.txt a.txt
602 git commit -m "duplicated file"
604 oid_root="$(calc_oid "$(git cat-file -p :a.txt)")"
605 oid_tree="$(calc_oid "$(git cat-file -p :foo/bar/baz/a.txt)")"
606 size="$(git cat-file -p :foo/bar/baz/a.txt | wc -c | awk '{ print $1 }')"
608 # only import objects under "foo"
609 git lfs migrate import --include="foo/**"
611 assert_pointer "refs/heads/master" "foo/bar/baz/a.txt" "$oid_tree" "$size"
612 assert_local_object "$oid_tree" "$size"
614 # "a.txt" is not under "foo" and therefore should not be in LFS
615 oid_root_after_migration="$(calc_oid "$(git cat-file -p :a.txt)")"
616 [ "$oid_root" = "$oid_root_after_migration" ]
620 begin_test "migrate import (--object-map)"
624 setup_multiple_local_branches
626 output_dir=$(mktemp -d)
628 git log --all --pretty='format:%H' > "${output_dir}/old_sha.txt"
629 git lfs migrate import --everything --object-map "${output_dir}/object-map.txt"
630 git log --all --pretty='format:%H' > "${output_dir}/new_sha.txt"
631 paste -d',' "${output_dir}/old_sha.txt" "${output_dir}/new_sha.txt" > "${output_dir}/expected-map.txt"
633 diff -u <(sort "${output_dir}/expected-map.txt") <(sort "${output_dir}/object-map.txt")
637 begin_test "migrate import (--include with space)"
641 setup_local_branch_with_space
643 oid="$(calc_oid "$(git cat-file -p :"a file.txt")")"
645 git lfs migrate import --include "a file.txt"
647 assert_pointer "refs/heads/master" "a file.txt" "$oid" 50
649 if [ 1 -ne "$(grep -c "a\[\[:space:\]\]file.txt" .gitattributes)" ]; then
650 echo >&2 "fatal: expected \"a[[:space:]]file.txt\" to appear in .gitattributes"
651 echo >&2 "fatal: got"
652 sed -e 's/^/ /g' < .gitattributes >&2
658 begin_test "migrate import (handle symbolic link)"
662 setup_local_branch_with_symlink
664 txt_oid="$(calc_oid "$(git cat-file -p :a.txt)")"
665 link_oid="$(calc_oid "$(git cat-file -p :link.txt)")"
667 git lfs migrate import --include="*.txt"
669 assert_pointer "refs/heads/master" "a.txt" "$txt_oid" "120"
671 assert_local_object "$txt_oid" "120"
672 # "link.txt" is a symbolic link so it should be not in LFS
673 refute_local_object "$link_oid" "5"
677 begin_test "migrate import (commit --allow-empty)"
681 reponame="migrate---allow-empty"
685 git commit --allow-empty -m "initial commit"
687 original_head="$(git rev-parse HEAD)"
688 git lfs migrate import --everything
689 migrated_head="$(git rev-parse HEAD)"
691 assert_ref_unmoved "HEAD" "$original_head" "$migrated_head"
695 begin_test "migrate import (multiple remotes)"
699 setup_multiple_remotes
701 original_master="$(git rev-parse master)"
703 git lfs migrate import
705 migrated_master="$(git rev-parse master)"
707 assert_ref_unmoved "master" "$original_master" "$migrated_master"
711 begin_test "migrate import (dirty copy, negative answer)"
715 setup_local_branch_with_dirty_copy
717 original_master="$(git rev-parse master)"
719 echo "n" | git lfs migrate import --everything 2>&1 | tee migrate.log
720 grep "migrate: working copy must not be dirty" migrate.log
722 migrated_master="$(git rev-parse master)"
724 assert_ref_unmoved "master" "$original_master" "$migrated_master"
728 begin_test "migrate import (dirty copy, unknown then negative answer)"
732 setup_local_branch_with_dirty_copy
734 original_master="$(git rev-parse master)"
736 echo "x\nn" | git lfs migrate import --everything 2>&1 | tee migrate.log
740 [ "2" -eq "$(grep -o "override changes in your working copy" migrate.log \
741 | wc -l | awk '{ print $1 }')" ]
742 grep "migrate: working copy must not be dirty" migrate.log
744 migrated_master="$(git rev-parse master)"
746 assert_ref_unmoved "master" "$original_master" "$migrated_master"
750 begin_test "migrate import (dirty copy, positive answer)"
754 setup_local_branch_with_dirty_copy
756 oid="$(calc_oid "$(git cat-file -p :a.txt)")"
758 echo "y" | git lfs migrate import --everything 2>&1 | tee migrate.log
759 grep "migrate: changes in your working copy will be overridden ..." \
762 assert_pointer "refs/heads/master" "a.txt" "$oid" "5"
763 assert_local_object "$oid" "5"
767 begin_test "migrate import (non-standard refs)"
771 setup_multiple_local_branches_non_standard
773 md_oid="$(calc_oid "$(git cat-file -p :a.md)")"
774 txt_oid="$(calc_oid "$(git cat-file -p :a.txt)")"
775 md_feature_oid="$(calc_oid "$(git cat-file -p my-feature:a.md)")"
777 git lfs migrate import --everything
779 assert_pointer "refs/heads/master" "a.md" "$md_oid" "140"
780 assert_pointer "refs/heads/master" "a.txt" "$txt_oid" "120"
781 assert_pointer "refs/pull/1/base" "a.md" "$md_oid" "140"
782 assert_pointer "refs/pull/1/base" "a.txt" "$txt_oid" "120"
784 assert_pointer "refs/heads/my-feature" "a.txt" "$txt_oid" "120"
785 assert_pointer "refs/pull/1/head" "a.txt" "$txt_oid" "120"
787 assert_local_object "$md_oid" "140"
788 assert_local_object "$txt_oid" "120"
789 assert_local_object "$md_feature_oid" "30"