]>
git.ipfire.org Git - thirdparty/git.git/blob - contrib/subtree/t/t7900-subtree.sh
3 # Copyright (c) 2012 Avery Pennaraum
4 # Copyright (c) 2015 Alexey Shumkin
6 test_description
='Basic porcelain support for subtrees
8 This test verifies the basic operation of the add, pull, merge
9 and split subcommands of git subtree.
12 TEST_DIRECTORY
=$
(pwd)/..
/..
/..
/t
15 . ..
/..
/..
/t
/test-lib.sh
17 subtree_test_create_repo
()
19 test_create_repo
"$1" &&
22 git config log.
date relative
35 test_debug
"echo \"check a:\" \"{$1}\""
36 test_debug
"echo \" b:\" \"{$2}\""
37 if [ "$1" = "$2" ]; then
46 git
reset --hard HEAD~
49 # Make sure no patch changes more than one file.
50 # The original set of commits changed only one file each.
51 # A multi-file change would imply that we pruned commits
60 elif [ "$x" = "commit:" ]; then
61 if [ -n "$commit" ]; then
73 test_create_commit
() (
77 mkdir
-p "$(dirname "$commit")" \
78 || error
"Could not create directory for commit"
79 echo "$commit" >"$commit" &&
80 git add
"$commit" || error
"Could not add commit"
81 git commit
-m "$commit" || error
"Could not commit"
86 git log
--pretty=format
:%s
-1
91 subtree_test_count
=$
(($subtree_test_count+1))
95 # Tests for 'git subtree add'
99 test_expect_success
'no merge from non-existent subtree' '
100 subtree_test_create_repo "$subtree_test_count" &&
101 subtree_test_create_repo "$subtree_test_count/sub proj" &&
102 test_create_commit "$subtree_test_count" main1 &&
103 test_create_commit "$subtree_test_count/sub proj" sub1 &&
105 cd "$subtree_test_count" &&
106 git fetch ./"sub proj" master &&
107 test_must_fail git subtree merge --prefix="sub dir" FETCH_HEAD
112 test_expect_success
'no pull from non-existent subtree' '
113 subtree_test_create_repo "$subtree_test_count" &&
114 subtree_test_create_repo "$subtree_test_count/sub proj" &&
115 test_create_commit "$subtree_test_count" main1 &&
116 test_create_commit "$subtree_test_count/sub proj" sub1 &&
118 cd "$subtree_test_count" &&
119 git fetch ./"sub proj" master &&
120 test_must_fail git subtree pull --prefix="sub dir" ./"sub proj" master
124 test_expect_success
'add subproj as subtree into sub dir/ with --prefix' '
125 subtree_test_create_repo "$subtree_test_count" &&
126 subtree_test_create_repo "$subtree_test_count/sub proj" &&
127 test_create_commit "$subtree_test_count" main1 &&
128 test_create_commit "$subtree_test_count/sub proj" sub1 &&
130 cd "$subtree_test_count" &&
131 git fetch ./"sub proj" master &&
132 git subtree add --prefix="sub dir" FETCH_HEAD &&
133 check_equal "$(last_commit_message)" "Add '\''sub dir/'\'' from commit '\''$(git rev-parse FETCH_HEAD)'\''"
138 test_expect_success
'add subproj as subtree into sub dir/ with --prefix and --message' '
139 subtree_test_create_repo "$subtree_test_count" &&
140 subtree_test_create_repo "$subtree_test_count/sub proj" &&
141 test_create_commit "$subtree_test_count" main1 &&
142 test_create_commit "$subtree_test_count/sub proj" sub1 &&
144 cd "$subtree_test_count" &&
145 git fetch ./"sub proj" master &&
146 git subtree add --prefix="sub dir" --message="Added subproject" FETCH_HEAD &&
147 check_equal "$(last_commit_message)" "Added subproject"
152 test_expect_success
'add subproj as subtree into sub dir/ with --prefix as -P and --message as -m' '
153 subtree_test_create_repo "$subtree_test_count" &&
154 subtree_test_create_repo "$subtree_test_count/sub proj" &&
155 test_create_commit "$subtree_test_count" main1 &&
156 test_create_commit "$subtree_test_count/sub proj" sub1 &&
158 cd "$subtree_test_count" &&
159 git fetch ./"sub proj" master &&
160 git subtree add -P "sub dir" -m "Added subproject" FETCH_HEAD &&
161 check_equal "$(last_commit_message)" "Added subproject"
166 test_expect_success
'add subproj as subtree into sub dir/ with --squash and --prefix and --message' '
167 subtree_test_create_repo "$subtree_test_count" &&
168 subtree_test_create_repo "$subtree_test_count/sub proj" &&
169 test_create_commit "$subtree_test_count" main1 &&
170 test_create_commit "$subtree_test_count/sub proj" sub1 &&
172 cd "$subtree_test_count" &&
173 git fetch ./"sub proj" master &&
174 git subtree add --prefix="sub dir" --message="Added subproject with squash" --squash FETCH_HEAD &&
175 check_equal "$(last_commit_message)" "Added subproject with squash"
180 # Tests for 'git subtree merge'
184 test_expect_success
'merge new subproj history into sub dir/ with --prefix' '
185 subtree_test_create_repo "$subtree_test_count" &&
186 subtree_test_create_repo "$subtree_test_count/sub proj" &&
187 test_create_commit "$subtree_test_count" main1 &&
188 test_create_commit "$subtree_test_count/sub proj" sub1 &&
190 cd "$subtree_test_count" &&
191 git fetch ./"sub proj" master &&
192 git subtree add --prefix="sub dir" FETCH_HEAD
194 test_create_commit "$subtree_test_count/sub proj" sub2 &&
196 cd "$subtree_test_count" &&
197 git fetch ./"sub proj" master &&
198 git subtree merge --prefix="sub dir" FETCH_HEAD &&
199 check_equal "$(last_commit_message)" \
200 "Merge commit '\''$(git rev-parse FETCH_HEAD)'\'' into master"
205 test_expect_success
'merge new subproj history into sub dir/ with --prefix and --message' '
206 subtree_test_create_repo "$subtree_test_count" &&
207 subtree_test_create_repo "$subtree_test_count/sub proj" &&
208 test_create_commit "$subtree_test_count" main1 &&
209 test_create_commit "$subtree_test_count/sub proj" sub1 &&
211 cd "$subtree_test_count" &&
212 git fetch ./"sub proj" master &&
213 git subtree add --prefix="sub dir" FETCH_HEAD
215 test_create_commit "$subtree_test_count/sub proj" sub2 &&
217 cd "$subtree_test_count" &&
218 git fetch ./"sub proj" master &&
219 git subtree merge --prefix="sub dir" --message="Merged changes from subproject" FETCH_HEAD &&
220 check_equal "$(last_commit_message)" "Merged changes from subproject"
225 test_expect_success
'merge new subproj history into sub dir/ with --squash and --prefix and --message' '
226 subtree_test_create_repo "$subtree_test_count/sub proj" &&
227 subtree_test_create_repo "$subtree_test_count" &&
228 test_create_commit "$subtree_test_count" main1 &&
229 test_create_commit "$subtree_test_count/sub proj" sub1 &&
231 cd "$subtree_test_count" &&
232 git fetch ./"sub proj" master &&
233 git subtree add --prefix="sub dir" FETCH_HEAD
235 test_create_commit "$subtree_test_count/sub proj" sub2 &&
237 cd "$subtree_test_count" &&
238 git fetch ./"sub proj" master &&
239 git subtree merge --prefix="sub dir" --message="Merged changes from subproject using squash" --squash FETCH_HEAD &&
240 check_equal "$(last_commit_message)" "Merged changes from subproject using squash"
245 test_expect_success
'merge the added subproj again, should do nothing' '
246 subtree_test_create_repo "$subtree_test_count" &&
247 subtree_test_create_repo "$subtree_test_count/sub proj" &&
248 test_create_commit "$subtree_test_count" main1 &&
249 test_create_commit "$subtree_test_count/sub proj" sub1 &&
251 cd "$subtree_test_count" &&
252 git fetch ./"sub proj" master &&
253 git subtree add --prefix="sub dir" FETCH_HEAD &&
254 # this shouldn not actually do anything, since FETCH_HEAD
255 # is already a parent
256 result=$(git merge -s ours -m "merge -s -ours" FETCH_HEAD) &&
257 check_equal "${result}" "Already up to date."
262 test_expect_success
'merge new subproj history into subdir/ with a slash appended to the argument of --prefix' '
263 test_create_repo "$test_count" &&
264 test_create_repo "$test_count/subproj" &&
265 test_create_commit "$test_count" main1 &&
266 test_create_commit "$test_count/subproj" sub1 &&
269 git fetch ./subproj master &&
270 git subtree add --prefix=subdir/ FETCH_HEAD
272 test_create_commit "$test_count/subproj" sub2 &&
275 git fetch ./subproj master &&
276 git subtree merge --prefix=subdir/ FETCH_HEAD &&
277 check_equal "$(last_commit_message)" \
278 "Merge commit '\''$(git rev-parse FETCH_HEAD)'\'' into master"
283 # Tests for 'git subtree split'
287 test_expect_success
'split requires option --prefix' '
288 subtree_test_create_repo "$subtree_test_count" &&
289 subtree_test_create_repo "$subtree_test_count/sub proj" &&
290 test_create_commit "$subtree_test_count" main1 &&
291 test_create_commit "$subtree_test_count/sub proj" sub1 &&
293 cd "$subtree_test_count" &&
294 git fetch ./"sub proj" master &&
295 git subtree add --prefix="sub dir" FETCH_HEAD &&
296 echo "You must provide the --prefix option." > expected &&
297 test_must_fail git subtree split > actual 2>&1 &&
298 test_debug "printf '"expected: "'" &&
299 test_debug "cat expected" &&
300 test_debug "printf '"actual: "'" &&
301 test_debug "cat actual" &&
302 test_cmp expected actual
307 test_expect_success
'split requires path given by option --prefix must exist' '
308 subtree_test_create_repo "$subtree_test_count" &&
309 subtree_test_create_repo "$subtree_test_count/sub proj" &&
310 test_create_commit "$subtree_test_count" main1 &&
311 test_create_commit "$subtree_test_count/sub proj" sub1 &&
313 cd "$subtree_test_count" &&
314 git fetch ./"sub proj" master &&
315 git subtree add --prefix="sub dir" FETCH_HEAD &&
316 echo "'\''non-existent-directory'\'' does not exist; use '\''git subtree add'\''" > expected &&
317 test_must_fail git subtree split --prefix=non-existent-directory > actual 2>&1 &&
318 test_debug "printf '"expected: "'" &&
319 test_debug "cat expected" &&
320 test_debug "printf '"actual: "'" &&
321 test_debug "cat actual" &&
322 test_cmp expected actual
327 test_expect_success
'split sub dir/ with --rejoin' '
328 subtree_test_create_repo "$subtree_test_count" &&
329 subtree_test_create_repo "$subtree_test_count/sub proj" &&
330 test_create_commit "$subtree_test_count" main1 &&
331 test_create_commit "$subtree_test_count/sub proj" sub1 &&
333 cd "$subtree_test_count" &&
334 git fetch ./"sub proj" master &&
335 git subtree add --prefix="sub dir" FETCH_HEAD
337 test_create_commit "$subtree_test_count" "sub dir"/main-sub1 &&
338 test_create_commit "$subtree_test_count" main2 &&
339 test_create_commit "$subtree_test_count/sub proj" sub2 &&
340 test_create_commit "$subtree_test_count" "sub dir"/main-sub2 &&
342 cd "$subtree_test_count" &&
343 git fetch ./"sub proj" master &&
344 git subtree merge --prefix="sub dir" FETCH_HEAD &&
345 split_hash=$(git subtree split --prefix="sub dir" --annotate="*") &&
346 git subtree split --prefix="sub dir" --annotate="*" --rejoin &&
347 check_equal "$(last_commit_message)" "Split '\''sub dir/'\'' into commit '\''$split_hash'\''"
352 test_expect_success
'split sub dir/ with --rejoin from scratch' '
353 subtree_test_create_repo "$subtree_test_count" &&
354 test_create_commit "$subtree_test_count" main1 &&
356 cd "$subtree_test_count" &&
358 echo file >"sub dir"/file &&
359 git add "sub dir/file" &&
360 git commit -m"sub dir file" &&
361 split_hash=$(git subtree split --prefix="sub dir" --rejoin) &&
362 git subtree split --prefix="sub dir" --rejoin &&
363 check_equal "$(last_commit_message)" "Split '\''sub dir/'\'' into commit '\''$split_hash'\''"
368 test_expect_success
'split sub dir/ with --rejoin and --message' '
369 subtree_test_create_repo "$subtree_test_count" &&
370 subtree_test_create_repo "$subtree_test_count/sub proj" &&
371 test_create_commit "$subtree_test_count" main1 &&
372 test_create_commit "$subtree_test_count/sub proj" sub1 &&
374 cd "$subtree_test_count" &&
375 git fetch ./"sub proj" master &&
376 git subtree add --prefix="sub dir" FETCH_HEAD
378 test_create_commit "$subtree_test_count" "sub dir"/main-sub1 &&
379 test_create_commit "$subtree_test_count" main2 &&
380 test_create_commit "$subtree_test_count/sub proj" sub2 &&
381 test_create_commit "$subtree_test_count" "sub dir"/main-sub2 &&
383 cd "$subtree_test_count" &&
384 git fetch ./"sub proj" master &&
385 git subtree merge --prefix="sub dir" FETCH_HEAD &&
386 git subtree split --prefix="sub dir" --message="Split & rejoin" --annotate="*" --rejoin &&
387 check_equal "$(last_commit_message)" "Split & rejoin"
392 test_expect_success
'split "sub dir"/ with --branch' '
393 subtree_test_create_repo "$subtree_test_count" &&
394 subtree_test_create_repo "$subtree_test_count/sub proj" &&
395 test_create_commit "$subtree_test_count" main1 &&
396 test_create_commit "$subtree_test_count/sub proj" sub1 &&
398 cd "$subtree_test_count" &&
399 git fetch ./"sub proj" master &&
400 git subtree add --prefix="sub dir" FETCH_HEAD
402 test_create_commit "$subtree_test_count" "sub dir"/main-sub1 &&
403 test_create_commit "$subtree_test_count" main2 &&
404 test_create_commit "$subtree_test_count/sub proj" sub2 &&
405 test_create_commit "$subtree_test_count" "sub dir"/main-sub2 &&
407 cd "$subtree_test_count" &&
408 git fetch ./"sub proj" master &&
409 git subtree merge --prefix="sub dir" FETCH_HEAD &&
410 split_hash=$(git subtree split --prefix="sub dir" --annotate="*") &&
411 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br &&
412 check_equal "$(git rev-parse subproj-br)" "$split_hash"
417 test_expect_success
'check hash of split' '
418 subtree_test_create_repo "$subtree_test_count" &&
419 subtree_test_create_repo "$subtree_test_count/sub proj" &&
420 test_create_commit "$subtree_test_count" main1 &&
421 test_create_commit "$subtree_test_count/sub proj" sub1 &&
423 cd "$subtree_test_count" &&
424 git fetch ./"sub proj" master &&
425 git subtree add --prefix="sub dir" FETCH_HEAD
427 test_create_commit "$subtree_test_count" "sub dir"/main-sub1 &&
428 test_create_commit "$subtree_test_count" main2 &&
429 test_create_commit "$subtree_test_count/sub proj" sub2 &&
430 test_create_commit "$subtree_test_count" "sub dir"/main-sub2 &&
432 cd "$subtree_test_count" &&
433 git fetch ./"sub proj" master &&
434 git subtree merge --prefix="sub dir" FETCH_HEAD &&
435 split_hash=$(git subtree split --prefix="sub dir" --annotate="*") &&
436 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br &&
437 check_equal "$(git rev-parse subproj-br)" "$split_hash" &&
438 # Check hash of split
439 new_hash=$(git rev-parse subproj-br^2) &&
442 subdir_hash=$(git rev-parse HEAD) &&
443 check_equal ''"$new_hash"'' "$subdir_hash"
449 test_expect_success
'split "sub dir"/ with --branch for an existing branch' '
450 subtree_test_create_repo "$subtree_test_count" &&
451 subtree_test_create_repo "$subtree_test_count/sub proj" &&
452 test_create_commit "$subtree_test_count" main1 &&
453 test_create_commit "$subtree_test_count/sub proj" sub1 &&
455 cd "$subtree_test_count" &&
456 git fetch ./"sub proj" master &&
457 git branch subproj-br FETCH_HEAD &&
458 git subtree add --prefix="sub dir" FETCH_HEAD
460 test_create_commit "$subtree_test_count" "sub dir"/main-sub1 &&
461 test_create_commit "$subtree_test_count" main2 &&
462 test_create_commit "$subtree_test_count/sub proj" sub2 &&
463 test_create_commit "$subtree_test_count" "sub dir"/main-sub2 &&
465 cd "$subtree_test_count" &&
466 git fetch ./"sub proj" master &&
467 git subtree merge --prefix="sub dir" FETCH_HEAD &&
468 split_hash=$(git subtree split --prefix="sub dir" --annotate="*") &&
469 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br &&
470 check_equal "$(git rev-parse subproj-br)" "$split_hash"
475 test_expect_success
'split "sub dir"/ with --branch for an incompatible branch' '
476 subtree_test_create_repo "$subtree_test_count" &&
477 subtree_test_create_repo "$subtree_test_count/sub proj" &&
478 test_create_commit "$subtree_test_count" main1 &&
479 test_create_commit "$subtree_test_count/sub proj" sub1 &&
481 cd "$subtree_test_count" &&
482 git branch init HEAD &&
483 git fetch ./"sub proj" master &&
484 git subtree add --prefix="sub dir" FETCH_HEAD
486 test_create_commit "$subtree_test_count" "sub dir"/main-sub1 &&
487 test_create_commit "$subtree_test_count" main2 &&
488 test_create_commit "$subtree_test_count/sub proj" sub2 &&
489 test_create_commit "$subtree_test_count" "sub dir"/main-sub2 &&
491 cd "$subtree_test_count" &&
492 git fetch ./"sub proj" master &&
493 git subtree merge --prefix="sub dir" FETCH_HEAD &&
494 test_must_fail git subtree split --prefix="sub dir" --branch init
503 test_expect_success
'make sure exactly the right set of files ends up in the subproj' '
504 subtree_test_create_repo "$subtree_test_count" &&
505 subtree_test_create_repo "$subtree_test_count/sub proj" &&
506 test_create_commit "$subtree_test_count" main1 &&
507 test_create_commit "$subtree_test_count/sub proj" sub1 &&
509 cd "$subtree_test_count" &&
510 git fetch ./"sub proj" master &&
511 git subtree add --prefix="sub dir" FETCH_HEAD
513 test_create_commit "$subtree_test_count" "sub dir"/main-sub1 &&
514 test_create_commit "$subtree_test_count" main2 &&
515 test_create_commit "$subtree_test_count/sub proj" sub2 &&
516 test_create_commit "$subtree_test_count" "sub dir"/main-sub2 &&
518 cd "$subtree_test_count" &&
519 git fetch ./"sub proj" master &&
520 git subtree merge --prefix="sub dir" FETCH_HEAD &&
521 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
523 test_create_commit "$subtree_test_count/sub proj" sub3 &&
524 test_create_commit "$subtree_test_count" "sub dir"/main-sub3 &&
526 cd "$subtree_test_count/sub proj" &&
527 git fetch .. subproj-br &&
530 test_create_commit "$subtree_test_count/sub proj" sub4 &&
532 cd "$subtree_test_count" &&
533 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
535 test_create_commit "$subtree_test_count" "sub dir"/main-sub4 &&
537 cd "$subtree_test_count" &&
538 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
541 cd "$subtree_test_count/sub proj" &&
542 git fetch .. subproj-br &&
543 git merge FETCH_HEAD &&
545 test_write_lines main-sub1 main-sub2 main-sub3 main-sub4 \
546 sub1 sub2 sub3 sub4 >expect &&
547 git ls-files >actual &&
548 test_cmp expect actual
553 test_expect_success
'make sure the subproj *only* contains commits that affect the "sub dir"' '
554 subtree_test_create_repo "$subtree_test_count" &&
555 subtree_test_create_repo "$subtree_test_count/sub proj" &&
556 test_create_commit "$subtree_test_count" main1 &&
557 test_create_commit "$subtree_test_count/sub proj" sub1 &&
559 cd "$subtree_test_count" &&
560 git fetch ./"sub proj" master &&
561 git subtree add --prefix="sub dir" FETCH_HEAD
563 test_create_commit "$subtree_test_count" "sub dir"/main-sub1 &&
564 test_create_commit "$subtree_test_count" main2 &&
565 test_create_commit "$subtree_test_count/sub proj" sub2 &&
566 test_create_commit "$subtree_test_count" "sub dir"/main-sub2 &&
568 cd "$subtree_test_count" &&
569 git fetch ./"sub proj" master &&
570 git subtree merge --prefix="sub dir" FETCH_HEAD &&
571 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
573 test_create_commit "$subtree_test_count/sub proj" sub3 &&
574 test_create_commit "$subtree_test_count" "sub dir"/main-sub3 &&
576 cd "$subtree_test_count/sub proj" &&
577 git fetch .. subproj-br &&
580 test_create_commit "$subtree_test_count/sub proj" sub4 &&
582 cd "$subtree_test_count" &&
583 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
585 test_create_commit "$subtree_test_count" "sub dir"/main-sub4 &&
587 cd "$subtree_test_count" &&
588 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
591 cd "$subtree_test_count/sub proj" &&
592 git fetch .. subproj-br &&
593 git merge FETCH_HEAD &&
595 test_write_lines main-sub1 main-sub2 main-sub3 main-sub4 \
596 sub1 sub2 sub3 sub4 >expect &&
597 git log --name-only --pretty=format:"" >log &&
598 sort <log | sed "/^\$/ d" >actual &&
599 test_cmp expect actual
604 test_expect_success
'make sure exactly the right set of files ends up in the mainline' '
605 subtree_test_create_repo "$subtree_test_count" &&
606 subtree_test_create_repo "$subtree_test_count/sub proj" &&
607 test_create_commit "$subtree_test_count" main1 &&
608 test_create_commit "$subtree_test_count/sub proj" sub1 &&
610 cd "$subtree_test_count" &&
611 git fetch ./"sub proj" master &&
612 git subtree add --prefix="sub dir" FETCH_HEAD
614 test_create_commit "$subtree_test_count" "sub dir"/main-sub1 &&
615 test_create_commit "$subtree_test_count" main2 &&
616 test_create_commit "$subtree_test_count/sub proj" sub2 &&
617 test_create_commit "$subtree_test_count" "sub dir"/main-sub2 &&
619 cd "$subtree_test_count" &&
620 git fetch ./"sub proj" master &&
621 git subtree merge --prefix="sub dir" FETCH_HEAD &&
622 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
624 test_create_commit "$subtree_test_count/sub proj" sub3 &&
625 test_create_commit "$subtree_test_count" "sub dir"/main-sub3 &&
627 cd "$subtree_test_count/sub proj" &&
628 git fetch .. subproj-br &&
631 test_create_commit "$subtree_test_count/sub proj" sub4 &&
633 cd "$subtree_test_count" &&
634 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
636 test_create_commit "$subtree_test_count" "sub dir"/main-sub4 &&
638 cd "$subtree_test_count" &&
639 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
642 cd "$subtree_test_count/sub proj" &&
643 git fetch .. subproj-br &&
647 cd "$subtree_test_count" &&
648 git subtree pull --prefix="sub dir" ./"sub proj" master &&
650 test_write_lines main1 main2 >chkm &&
651 test_write_lines main-sub1 main-sub2 main-sub3 main-sub4 >chkms &&
652 sed "s,^,sub dir/," chkms >chkms_sub &&
653 test_write_lines sub1 sub2 sub3 sub4 >chks &&
654 sed "s,^,sub dir/," chks >chks_sub &&
656 cat chkm chkms_sub chks_sub >expect &&
657 git ls-files >actual &&
658 test_cmp expect actual
663 test_expect_success
'make sure each filename changed exactly once in the entire history' '
664 subtree_test_create_repo "$subtree_test_count" &&
665 subtree_test_create_repo "$subtree_test_count/sub proj" &&
666 test_create_commit "$subtree_test_count" main1 &&
667 test_create_commit "$subtree_test_count/sub proj" sub1 &&
669 cd "$subtree_test_count" &&
670 git config log.date relative &&
671 git fetch ./"sub proj" master &&
672 git subtree add --prefix="sub dir" FETCH_HEAD
674 test_create_commit "$subtree_test_count" "sub dir"/main-sub1 &&
675 test_create_commit "$subtree_test_count" main2 &&
676 test_create_commit "$subtree_test_count/sub proj" sub2 &&
677 test_create_commit "$subtree_test_count" "sub dir"/main-sub2 &&
679 cd "$subtree_test_count" &&
680 git fetch ./"sub proj" master &&
681 git subtree merge --prefix="sub dir" FETCH_HEAD &&
682 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
684 test_create_commit "$subtree_test_count/sub proj" sub3 &&
685 test_create_commit "$subtree_test_count" "sub dir"/main-sub3 &&
687 cd "$subtree_test_count/sub proj" &&
688 git fetch .. subproj-br &&
691 test_create_commit "$subtree_test_count/sub proj" sub4 &&
693 cd "$subtree_test_count" &&
694 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
696 test_create_commit "$subtree_test_count" "sub dir"/main-sub4 &&
698 cd "$subtree_test_count" &&
699 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
702 cd "$subtree_test_count/sub proj" &&
703 git fetch .. subproj-br &&
707 cd "$subtree_test_count" &&
708 git subtree pull --prefix="sub dir" ./"sub proj" master &&
710 test_write_lines main1 main2 >chkm &&
711 test_write_lines sub1 sub2 sub3 sub4 >chks &&
712 test_write_lines main-sub1 main-sub2 main-sub3 main-sub4 >chkms &&
713 sed "s,^,sub dir/," chkms >chkms_sub &&
715 # main-sub?? and /"sub dir"/main-sub?? both change, because those are the
716 # changes that were split into their own history. And "sub dir"/sub?? never
717 # change, since they were *only* changed in the subtree branch.
718 git log --name-only --pretty=format:"" >log &&
719 sort <log >sorted-log &&
720 sed "/^$/ d" sorted-log >actual &&
722 cat chkms chkm chks chkms_sub >expect-unsorted &&
723 sort expect-unsorted >expect &&
724 test_cmp expect actual
729 test_expect_success
'make sure the --rejoin commits never make it into subproj' '
730 subtree_test_create_repo "$subtree_test_count" &&
731 subtree_test_create_repo "$subtree_test_count/sub proj" &&
732 test_create_commit "$subtree_test_count" main1 &&
733 test_create_commit "$subtree_test_count/sub proj" sub1 &&
735 cd "$subtree_test_count" &&
736 git fetch ./"sub proj" master &&
737 git subtree add --prefix="sub dir" FETCH_HEAD
739 test_create_commit "$subtree_test_count" "sub dir"/main-sub1 &&
740 test_create_commit "$subtree_test_count" main2 &&
741 test_create_commit "$subtree_test_count/sub proj" sub2 &&
742 test_create_commit "$subtree_test_count" "sub dir"/main-sub2 &&
744 cd "$subtree_test_count" &&
745 git fetch ./"sub proj" master &&
746 git subtree merge --prefix="sub dir" FETCH_HEAD &&
747 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
749 test_create_commit "$subtree_test_count/sub proj" sub3 &&
750 test_create_commit "$subtree_test_count" "sub dir"/main-sub3 &&
752 cd "$subtree_test_count/sub proj" &&
753 git fetch .. subproj-br &&
756 test_create_commit "$subtree_test_count/sub proj" sub4 &&
758 cd "$subtree_test_count" &&
759 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
761 test_create_commit "$subtree_test_count" "sub dir"/main-sub4 &&
763 cd "$subtree_test_count" &&
764 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
767 cd "$subtree_test_count/sub proj" &&
768 git fetch .. subproj-br &&
772 cd "$subtree_test_count" &&
773 git subtree pull --prefix="sub dir" ./"sub proj" master &&
774 check_equal "$(git log --pretty=format:"%s" HEAD^2 | grep -i split)" ""
779 test_expect_success
'make sure no "git subtree" tagged commits make it into subproj' '
780 subtree_test_create_repo "$subtree_test_count" &&
781 subtree_test_create_repo "$subtree_test_count/sub proj" &&
782 test_create_commit "$subtree_test_count" main1 &&
783 test_create_commit "$subtree_test_count/sub proj" sub1 &&
785 cd "$subtree_test_count" &&
786 git fetch ./"sub proj" master &&
787 git subtree add --prefix="sub dir" FETCH_HEAD
789 test_create_commit "$subtree_test_count" "sub dir"/main-sub1 &&
790 test_create_commit "$subtree_test_count" main2 &&
791 test_create_commit "$subtree_test_count/sub proj" sub2 &&
792 test_create_commit "$subtree_test_count" "sub dir"/main-sub2 &&
794 cd "$subtree_test_count" &&
795 git fetch ./"sub proj" master &&
796 git subtree merge --prefix="sub dir" FETCH_HEAD &&
797 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
799 test_create_commit "$subtree_test_count/sub proj" sub3 &&
800 test_create_commit "$subtree_test_count" "sub dir"/main-sub3 &&
802 cd "$subtree_test_count/sub proj" &&
803 git fetch .. subproj-br &&
806 test_create_commit "$subtree_test_count/sub proj" sub4 &&
808 cd "$subtree_test_count" &&
809 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
811 test_create_commit "$subtree_test_count" "sub dir"/main-sub4 &&
813 cd "$subtree_test_count" &&
814 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
817 cd "$subtree_test_count/sub proj" &&
818 git fetch .. subproj-br &&
822 cd "$subtree_test_count" &&
823 git subtree pull --prefix="sub dir" ./"sub proj" master &&
825 # They are meaningless to subproj since one side of the merge refers to the mainline
826 check_equal "$(git log --pretty=format:"%s%n%b" HEAD^2 | grep "git-subtree.*:")" ""
835 test_expect_success
'make sure "git subtree split" find the correct parent' '
836 subtree_test_create_repo "$subtree_test_count" &&
837 subtree_test_create_repo "$subtree_test_count/sub proj" &&
838 test_create_commit "$subtree_test_count" main1 &&
839 test_create_commit "$subtree_test_count/sub proj" sub1 &&
841 cd "$subtree_test_count" &&
842 git fetch ./"sub proj" master &&
843 git subtree add --prefix="sub dir" FETCH_HEAD
845 test_create_commit "$subtree_test_count/sub proj" sub2 &&
847 cd "$subtree_test_count" &&
848 git fetch ./"sub proj" master &&
849 git branch subproj-ref FETCH_HEAD &&
850 git subtree merge --prefix="sub dir" FETCH_HEAD
852 test_create_commit "$subtree_test_count" "sub dir"/main-sub1 &&
854 cd "$subtree_test_count" &&
855 git subtree split --prefix="sub dir" --branch subproj-br &&
857 # at this point, the new commit parent should be subproj-ref, if it is
858 # not, something went wrong (the "newparent" of "master~" commit should
859 # have been sub2, but it was not, because its cache was not set to
861 check_equal "$(git log --pretty=format:%P -1 subproj-br)" "$(git rev-parse subproj-ref)"
866 test_expect_success
'split a new subtree without --onto option' '
867 subtree_test_create_repo "$subtree_test_count" &&
868 subtree_test_create_repo "$subtree_test_count/sub proj" &&
869 test_create_commit "$subtree_test_count" main1 &&
870 test_create_commit "$subtree_test_count/sub proj" sub1 &&
872 cd "$subtree_test_count" &&
873 git fetch ./"sub proj" master &&
874 git subtree add --prefix="sub dir" FETCH_HEAD
876 test_create_commit "$subtree_test_count/sub proj" sub2 &&
878 cd "$subtree_test_count" &&
879 git fetch ./"sub proj" master &&
880 git subtree merge --prefix="sub dir" FETCH_HEAD
882 test_create_commit "$subtree_test_count" "sub dir"/main-sub1 &&
884 cd "$subtree_test_count" &&
885 git subtree split --prefix="sub dir" --branch subproj-br
887 mkdir "$subtree_test_count"/"sub dir2" &&
888 test_create_commit "$subtree_test_count" "sub dir2"/main-sub2 &&
890 cd "$subtree_test_count" &&
892 # also test that we still can split out an entirely new subtree
893 # if the parent of the first commit in the tree is not empty,
894 # then the new subtree has accidentally been attached to something
895 git subtree split --prefix="sub dir2" --branch subproj2-br &&
896 check_equal "$(git log --pretty=format:%P -1 subproj2-br)" ""
901 test_expect_success
'verify one file change per commit' '
902 subtree_test_create_repo "$subtree_test_count" &&
903 subtree_test_create_repo "$subtree_test_count/sub proj" &&
904 test_create_commit "$subtree_test_count" main1 &&
905 test_create_commit "$subtree_test_count/sub proj" sub1 &&
907 cd "$subtree_test_count" &&
908 git fetch ./"sub proj" master &&
909 git branch sub1 FETCH_HEAD &&
910 git subtree add --prefix="sub dir" sub1
912 test_create_commit "$subtree_test_count/sub proj" sub2 &&
914 cd "$subtree_test_count" &&
915 git fetch ./"sub proj" master &&
916 git subtree merge --prefix="sub dir" FETCH_HEAD
918 test_create_commit "$subtree_test_count" "sub dir"/main-sub1 &&
920 cd "$subtree_test_count" &&
921 git subtree split --prefix="sub dir" --branch subproj-br
923 mkdir "$subtree_test_count"/"sub dir2" &&
924 test_create_commit "$subtree_test_count" "sub dir2"/main-sub2 &&
926 cd "$subtree_test_count" &&
927 git subtree split --prefix="sub dir2" --branch subproj2-br &&
930 git log --pretty=format:"commit: %H" | join_commits |
932 while read commit a b; do
933 test_debug "echo Verifying commit $commit"
934 test_debug "echo a: $a"
935 test_debug "echo b: $b"
945 test_expect_success
'push split to subproj' '
946 subtree_test_create_repo "$subtree_test_count" &&
947 subtree_test_create_repo "$subtree_test_count/sub proj" &&
948 test_create_commit "$subtree_test_count" main1 &&
949 test_create_commit "$subtree_test_count/sub proj" sub1 &&
951 cd "$subtree_test_count" &&
952 git fetch ./"sub proj" master &&
953 git subtree add --prefix="sub dir" FETCH_HEAD
955 test_create_commit "$subtree_test_count" "sub dir"/main-sub1 &&
956 test_create_commit "$subtree_test_count" main2 &&
957 test_create_commit "$subtree_test_count/sub proj" sub2 &&
958 test_create_commit "$subtree_test_count" "sub dir"/main-sub2 &&
960 cd $subtree_test_count/"sub proj" &&
961 git branch sub-branch-1 &&
963 git fetch ./"sub proj" master &&
964 git subtree merge --prefix="sub dir" FETCH_HEAD
966 test_create_commit "$subtree_test_count" "sub dir"/main-sub3 &&
968 cd "$subtree_test_count" &&
969 git subtree push ./"sub proj" --prefix "sub dir" sub-branch-1 &&
971 git checkout sub-branch-1 &&
972 check_equal "$(last_commit_message)" "sub dir/main-sub3"
977 # This test covers 2 cases in subtree split copy_or_skip code
978 # 1) Merges where one parent is a superset of the changes of the other
979 # parent regarding changes to the subtree, in this case the merge
980 # commit should be copied
981 # 2) Merges where only one parent operate on the subtree, and the merge
982 # commit should be skipped
984 # (1) is checked by ensuring subtree_tip is a descendent of subtree_branch
985 # (2) should have a check added (not_a_subtree_change shouldn't be present
986 # on the produced subtree)
988 # Other related cases which are not tested (or currently handled correctly)
989 # - Case (1) where there are more than 2 parents, it will sometimes correctly copy
990 # the merge, and sometimes not
991 # - Merge commit where both parents have same tree as the merge, currently
992 # will always be skipped, even if they reached that state via different
997 test_expect_success
'subtree descendant check' '
998 subtree_test_create_repo "$subtree_test_count" &&
999 test_create_commit "$subtree_test_count" folder_subtree/a &&
1001 cd "$subtree_test_count" &&
1004 test_create_commit "$subtree_test_count" folder_subtree/0 &&
1005 test_create_commit "$subtree_test_count" folder_subtree/b &&
1006 cherry=$(cd "$subtree_test_count"; git rev-parse HEAD) &&
1008 cd "$subtree_test_count" &&
1011 test_create_commit "$subtree_test_count" commit_on_branch &&
1013 cd "$subtree_test_count" &&
1014 git cherry-pick $cherry &&
1015 git checkout master &&
1016 git merge -m "merge should be kept on subtree" branch &&
1017 git branch no_subtree_work_branch
1019 test_create_commit "$subtree_test_count" folder_subtree/d &&
1021 cd "$subtree_test_count" &&
1022 git checkout no_subtree_work_branch
1024 test_create_commit "$subtree_test_count" not_a_subtree_change &&
1026 cd "$subtree_test_count" &&
1027 git checkout master &&
1028 git merge -m "merge should be skipped on subtree" no_subtree_work_branch &&
1030 git subtree split --prefix folder_subtree/ --branch subtree_tip master &&
1031 git subtree split --prefix folder_subtree/ --branch subtree_branch branch &&
1032 check_equal $(git rev-list --count subtree_tip..subtree_branch) 0