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
()
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)" "Merge commit '\''$(git rev-parse FETCH_HEAD)'\''"
204 test_expect_success
'merge new subproj history into sub dir/ with --prefix and --message' '
205 subtree_test_create_repo "$subtree_test_count" &&
206 subtree_test_create_repo "$subtree_test_count/sub proj" &&
207 test_create_commit "$subtree_test_count" main1 &&
208 test_create_commit "$subtree_test_count/sub proj" sub1 &&
210 cd "$subtree_test_count" &&
211 git fetch ./"sub proj" master &&
212 git subtree add --prefix="sub dir" FETCH_HEAD
214 test_create_commit "$subtree_test_count/sub proj" sub2 &&
216 cd "$subtree_test_count" &&
217 git fetch ./"sub proj" master &&
218 git subtree merge --prefix="sub dir" --message="Merged changes from subproject" FETCH_HEAD &&
219 check_equal "$(last_commit_message)" "Merged changes from subproject"
224 test_expect_success
'merge new subproj history into sub dir/ with --squash and --prefix and --message' '
225 subtree_test_create_repo "$subtree_test_count/sub proj" &&
226 subtree_test_create_repo "$subtree_test_count" &&
227 test_create_commit "$subtree_test_count" main1 &&
228 test_create_commit "$subtree_test_count/sub proj" sub1 &&
230 cd "$subtree_test_count" &&
231 git fetch ./"sub proj" master &&
232 git subtree add --prefix="sub dir" FETCH_HEAD
234 test_create_commit "$subtree_test_count/sub proj" sub2 &&
236 cd "$subtree_test_count" &&
237 git fetch ./"sub proj" master &&
238 git subtree merge --prefix="sub dir" --message="Merged changes from subproject using squash" --squash FETCH_HEAD &&
239 check_equal "$(last_commit_message)" "Merged changes from subproject using squash"
244 test_expect_success
'merge the added subproj again, should do nothing' '
245 subtree_test_create_repo "$subtree_test_count" &&
246 subtree_test_create_repo "$subtree_test_count/sub proj" &&
247 test_create_commit "$subtree_test_count" main1 &&
248 test_create_commit "$subtree_test_count/sub proj" sub1 &&
250 cd "$subtree_test_count" &&
251 git fetch ./"sub proj" master &&
252 git subtree add --prefix="sub dir" FETCH_HEAD &&
253 # this shouldn not actually do anything, since FETCH_HEAD
254 # is already a parent
255 result=$(git merge -s ours -m "merge -s -ours" FETCH_HEAD) &&
256 check_equal "${result}" "Already up-to-date."
261 test_expect_success
'merge new subproj history into subdir/ with a slash appended to the argument of --prefix' '
262 test_create_repo "$test_count" &&
263 test_create_repo "$test_count/subproj" &&
264 test_create_commit "$test_count" main1 &&
265 test_create_commit "$test_count/subproj" sub1 &&
268 git fetch ./subproj master &&
269 git subtree add --prefix=subdir/ FETCH_HEAD
271 test_create_commit "$test_count/subproj" sub2 &&
274 git fetch ./subproj master &&
275 git subtree merge --prefix=subdir/ FETCH_HEAD &&
276 check_equal "$(last_commit_message)" "Merge commit '\''$(git rev-parse FETCH_HEAD)'\''"
281 # Tests for 'git subtree split'
285 test_expect_success
'split requires option --prefix' '
286 subtree_test_create_repo "$subtree_test_count" &&
287 subtree_test_create_repo "$subtree_test_count/sub proj" &&
288 test_create_commit "$subtree_test_count" main1 &&
289 test_create_commit "$subtree_test_count/sub proj" sub1 &&
291 cd "$subtree_test_count" &&
292 git fetch ./"sub proj" master &&
293 git subtree add --prefix="sub dir" FETCH_HEAD &&
294 echo "You must provide the --prefix option." > expected &&
295 test_must_fail git subtree split > actual 2>&1 &&
296 test_debug "printf '"expected: "'" &&
297 test_debug "cat expected" &&
298 test_debug "printf '"actual: "'" &&
299 test_debug "cat actual" &&
300 test_cmp expected actual
305 test_expect_success
'split requires path given by option --prefix must exist' '
306 subtree_test_create_repo "$subtree_test_count" &&
307 subtree_test_create_repo "$subtree_test_count/sub proj" &&
308 test_create_commit "$subtree_test_count" main1 &&
309 test_create_commit "$subtree_test_count/sub proj" sub1 &&
311 cd "$subtree_test_count" &&
312 git fetch ./"sub proj" master &&
313 git subtree add --prefix="sub dir" FETCH_HEAD &&
314 echo "'\''non-existent-directory'\'' does not exist; use '\''git subtree add'\''" > expected &&
315 test_must_fail git subtree split --prefix=non-existent-directory > actual 2>&1 &&
316 test_debug "printf '"expected: "'" &&
317 test_debug "cat expected" &&
318 test_debug "printf '"actual: "'" &&
319 test_debug "cat actual" &&
320 test_cmp expected actual
325 test_expect_success
'split sub dir/ with --rejoin' '
326 subtree_test_create_repo "$subtree_test_count" &&
327 subtree_test_create_repo "$subtree_test_count/sub proj" &&
328 test_create_commit "$subtree_test_count" main1 &&
329 test_create_commit "$subtree_test_count/sub proj" sub1 &&
331 cd "$subtree_test_count" &&
332 git fetch ./"sub proj" master &&
333 git subtree add --prefix="sub dir" FETCH_HEAD
335 test_create_commit "$subtree_test_count" "sub dir"/main-sub1 &&
336 test_create_commit "$subtree_test_count" main2 &&
337 test_create_commit "$subtree_test_count/sub proj" sub2 &&
338 test_create_commit "$subtree_test_count" "sub dir"/main-sub2 &&
340 cd "$subtree_test_count" &&
341 git fetch ./"sub proj" master &&
342 git subtree merge --prefix="sub dir" FETCH_HEAD &&
343 split_hash=$(git subtree split --prefix="sub dir" --annotate="*") &&
344 git subtree split --prefix="sub dir" --annotate="*" --rejoin &&
345 check_equal "$(last_commit_message)" "Split '\''sub dir/'\'' into commit '\''$split_hash'\''"
350 test_expect_success
'split sub dir/ with --rejoin and --message' '
351 subtree_test_create_repo "$subtree_test_count" &&
352 subtree_test_create_repo "$subtree_test_count/sub proj" &&
353 test_create_commit "$subtree_test_count" main1 &&
354 test_create_commit "$subtree_test_count/sub proj" sub1 &&
356 cd "$subtree_test_count" &&
357 git fetch ./"sub proj" master &&
358 git subtree add --prefix="sub dir" FETCH_HEAD
360 test_create_commit "$subtree_test_count" "sub dir"/main-sub1 &&
361 test_create_commit "$subtree_test_count" main2 &&
362 test_create_commit "$subtree_test_count/sub proj" sub2 &&
363 test_create_commit "$subtree_test_count" "sub dir"/main-sub2 &&
365 cd "$subtree_test_count" &&
366 git fetch ./"sub proj" master &&
367 git subtree merge --prefix="sub dir" FETCH_HEAD &&
368 git subtree split --prefix="sub dir" --message="Split & rejoin" --annotate="*" --rejoin &&
369 check_equal "$(last_commit_message)" "Split & rejoin"
374 test_expect_success
'split "sub dir"/ with --branch' '
375 subtree_test_create_repo "$subtree_test_count" &&
376 subtree_test_create_repo "$subtree_test_count/sub proj" &&
377 test_create_commit "$subtree_test_count" main1 &&
378 test_create_commit "$subtree_test_count/sub proj" sub1 &&
380 cd "$subtree_test_count" &&
381 git fetch ./"sub proj" master &&
382 git subtree add --prefix="sub dir" FETCH_HEAD
384 test_create_commit "$subtree_test_count" "sub dir"/main-sub1 &&
385 test_create_commit "$subtree_test_count" main2 &&
386 test_create_commit "$subtree_test_count/sub proj" sub2 &&
387 test_create_commit "$subtree_test_count" "sub dir"/main-sub2 &&
389 cd "$subtree_test_count" &&
390 git fetch ./"sub proj" master &&
391 git subtree merge --prefix="sub dir" FETCH_HEAD &&
392 split_hash=$(git subtree split --prefix="sub dir" --annotate="*") &&
393 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br &&
394 check_equal "$(git rev-parse subproj-br)" "$split_hash"
399 test_expect_success
'check hash of split' '
400 subtree_test_create_repo "$subtree_test_count" &&
401 subtree_test_create_repo "$subtree_test_count/sub proj" &&
402 test_create_commit "$subtree_test_count" main1 &&
403 test_create_commit "$subtree_test_count/sub proj" sub1 &&
405 cd "$subtree_test_count" &&
406 git fetch ./"sub proj" master &&
407 git subtree add --prefix="sub dir" FETCH_HEAD
409 test_create_commit "$subtree_test_count" "sub dir"/main-sub1 &&
410 test_create_commit "$subtree_test_count" main2 &&
411 test_create_commit "$subtree_test_count/sub proj" sub2 &&
412 test_create_commit "$subtree_test_count" "sub dir"/main-sub2 &&
414 cd "$subtree_test_count" &&
415 git fetch ./"sub proj" master &&
416 git subtree merge --prefix="sub dir" FETCH_HEAD &&
417 split_hash=$(git subtree split --prefix="sub dir" --annotate="*") &&
418 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br &&
419 check_equal "$(git rev-parse subproj-br)" "$split_hash" &&
420 # Check hash of split
421 new_hash=$(git rev-parse subproj-br^2) &&
424 subdir_hash=$(git rev-parse HEAD) &&
425 check_equal ''"$new_hash"'' "$subdir_hash"
431 test_expect_success
'split "sub dir"/ with --branch for an existing branch' '
432 subtree_test_create_repo "$subtree_test_count" &&
433 subtree_test_create_repo "$subtree_test_count/sub proj" &&
434 test_create_commit "$subtree_test_count" main1 &&
435 test_create_commit "$subtree_test_count/sub proj" sub1 &&
437 cd "$subtree_test_count" &&
438 git fetch ./"sub proj" master &&
439 git branch subproj-br FETCH_HEAD &&
440 git subtree add --prefix="sub dir" FETCH_HEAD
442 test_create_commit "$subtree_test_count" "sub dir"/main-sub1 &&
443 test_create_commit "$subtree_test_count" main2 &&
444 test_create_commit "$subtree_test_count/sub proj" sub2 &&
445 test_create_commit "$subtree_test_count" "sub dir"/main-sub2 &&
447 cd "$subtree_test_count" &&
448 git fetch ./"sub proj" master &&
449 git subtree merge --prefix="sub dir" FETCH_HEAD &&
450 split_hash=$(git subtree split --prefix="sub dir" --annotate="*") &&
451 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br &&
452 check_equal "$(git rev-parse subproj-br)" "$split_hash"
457 test_expect_success
'split "sub dir"/ with --branch for an incompatible branch' '
458 subtree_test_create_repo "$subtree_test_count" &&
459 subtree_test_create_repo "$subtree_test_count/sub proj" &&
460 test_create_commit "$subtree_test_count" main1 &&
461 test_create_commit "$subtree_test_count/sub proj" sub1 &&
463 cd "$subtree_test_count" &&
464 git branch init HEAD &&
465 git fetch ./"sub proj" master &&
466 git subtree add --prefix="sub dir" FETCH_HEAD
468 test_create_commit "$subtree_test_count" "sub dir"/main-sub1 &&
469 test_create_commit "$subtree_test_count" main2 &&
470 test_create_commit "$subtree_test_count/sub proj" sub2 &&
471 test_create_commit "$subtree_test_count" "sub dir"/main-sub2 &&
473 cd "$subtree_test_count" &&
474 git fetch ./"sub proj" master &&
475 git subtree merge --prefix="sub dir" FETCH_HEAD &&
476 test_must_fail git subtree split --prefix="sub dir" --branch init
485 test_expect_success
'make sure exactly the right set of files ends up in the subproj' '
486 subtree_test_create_repo "$subtree_test_count" &&
487 subtree_test_create_repo "$subtree_test_count/sub proj" &&
488 test_create_commit "$subtree_test_count" main1 &&
489 test_create_commit "$subtree_test_count/sub proj" sub1 &&
491 cd "$subtree_test_count" &&
492 git fetch ./"sub proj" master &&
493 git subtree add --prefix="sub dir" FETCH_HEAD
495 test_create_commit "$subtree_test_count" "sub dir"/main-sub1 &&
496 test_create_commit "$subtree_test_count" main2 &&
497 test_create_commit "$subtree_test_count/sub proj" sub2 &&
498 test_create_commit "$subtree_test_count" "sub dir"/main-sub2 &&
500 cd "$subtree_test_count" &&
501 git fetch ./"sub proj" master &&
502 git subtree merge --prefix="sub dir" FETCH_HEAD &&
503 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
505 test_create_commit "$subtree_test_count/sub proj" sub3 &&
506 test_create_commit "$subtree_test_count" "sub dir"/main-sub3 &&
508 cd "$subtree_test_count/sub proj" &&
509 git fetch .. subproj-br &&
512 test_create_commit "$subtree_test_count/sub proj" sub4 &&
514 cd "$subtree_test_count" &&
515 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
517 test_create_commit "$subtree_test_count" "sub dir"/main-sub4 &&
519 cd "$subtree_test_count" &&
520 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
523 cd "$subtree_test_count/sub proj" &&
524 git fetch .. subproj-br &&
525 git merge FETCH_HEAD &&
531 chks_sub=$(cat <<TXT | sed '\''s,^,sub dir/,'\''
539 chkms_sub=$(cat <<TXT | sed '\''s,^,sub dir/,'\''
544 subfiles=$(git ls-files) &&
545 check_equal "$subfiles" "$chkms
551 test_expect_success
'make sure the subproj *only* contains commits that affect the "sub dir"' '
552 subtree_test_create_repo "$subtree_test_count" &&
553 subtree_test_create_repo "$subtree_test_count/sub proj" &&
554 test_create_commit "$subtree_test_count" main1 &&
555 test_create_commit "$subtree_test_count/sub proj" sub1 &&
557 cd "$subtree_test_count" &&
558 git fetch ./"sub proj" master &&
559 git subtree add --prefix="sub dir" FETCH_HEAD
561 test_create_commit "$subtree_test_count" "sub dir"/main-sub1 &&
562 test_create_commit "$subtree_test_count" main2 &&
563 test_create_commit "$subtree_test_count/sub proj" sub2 &&
564 test_create_commit "$subtree_test_count" "sub dir"/main-sub2 &&
566 cd "$subtree_test_count" &&
567 git fetch ./"sub proj" master &&
568 git subtree merge --prefix="sub dir" FETCH_HEAD &&
569 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
571 test_create_commit "$subtree_test_count/sub proj" sub3 &&
572 test_create_commit "$subtree_test_count" "sub dir"/main-sub3 &&
574 cd "$subtree_test_count/sub proj" &&
575 git fetch .. subproj-br &&
578 test_create_commit "$subtree_test_count/sub proj" sub4 &&
580 cd "$subtree_test_count" &&
581 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
583 test_create_commit "$subtree_test_count" "sub dir"/main-sub4 &&
585 cd "$subtree_test_count" &&
586 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
589 cd "$subtree_test_count/sub proj" &&
590 git fetch .. subproj-br &&
591 git merge FETCH_HEAD &&
597 chks_sub=$(cat <<TXT | sed '\''s,^,sub dir/,'\''
605 chkms_sub=$(cat <<TXT | sed '\''s,^,sub dir/,'\''
609 allchanges=$(git log --name-only --pretty=format:"" | sort | sed "/^$/d") &&
610 check_equal "$allchanges" "$chkms
616 test_expect_success
'make sure exactly the right set of files ends up in the mainline' '
617 subtree_test_create_repo "$subtree_test_count" &&
618 subtree_test_create_repo "$subtree_test_count/sub proj" &&
619 test_create_commit "$subtree_test_count" main1 &&
620 test_create_commit "$subtree_test_count/sub proj" sub1 &&
622 cd "$subtree_test_count" &&
623 git fetch ./"sub proj" master &&
624 git subtree add --prefix="sub dir" FETCH_HEAD
626 test_create_commit "$subtree_test_count" "sub dir"/main-sub1 &&
627 test_create_commit "$subtree_test_count" main2 &&
628 test_create_commit "$subtree_test_count/sub proj" sub2 &&
629 test_create_commit "$subtree_test_count" "sub dir"/main-sub2 &&
631 cd "$subtree_test_count" &&
632 git fetch ./"sub proj" master &&
633 git subtree merge --prefix="sub dir" FETCH_HEAD &&
634 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
636 test_create_commit "$subtree_test_count/sub proj" sub3 &&
637 test_create_commit "$subtree_test_count" "sub dir"/main-sub3 &&
639 cd "$subtree_test_count/sub proj" &&
640 git fetch .. subproj-br &&
643 test_create_commit "$subtree_test_count/sub proj" sub4 &&
645 cd "$subtree_test_count" &&
646 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
648 test_create_commit "$subtree_test_count" "sub dir"/main-sub4 &&
650 cd "$subtree_test_count" &&
651 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
654 cd "$subtree_test_count/sub proj" &&
655 git fetch .. subproj-br &&
659 cd "$subtree_test_count" &&
660 git subtree pull --prefix="sub dir" ./"sub proj" master &&
668 chks_sub=$(cat <<TXT | sed '\''s,^,sub dir/,'\''
676 chkms_sub=$(cat <<TXT | sed '\''s,^,sub dir/,'\''
680 mainfiles=$(git ls-files) &&
681 check_equal "$mainfiles" "$chkm
688 test_expect_success
'make sure each filename changed exactly once in the entire history' '
689 subtree_test_create_repo "$subtree_test_count" &&
690 subtree_test_create_repo "$subtree_test_count/sub proj" &&
691 test_create_commit "$subtree_test_count" main1 &&
692 test_create_commit "$subtree_test_count/sub proj" sub1 &&
694 cd "$subtree_test_count" &&
695 git config log.date relative
696 git fetch ./"sub proj" master &&
697 git subtree add --prefix="sub dir" FETCH_HEAD
699 test_create_commit "$subtree_test_count" "sub dir"/main-sub1 &&
700 test_create_commit "$subtree_test_count" main2 &&
701 test_create_commit "$subtree_test_count/sub proj" sub2 &&
702 test_create_commit "$subtree_test_count" "sub dir"/main-sub2 &&
704 cd "$subtree_test_count" &&
705 git fetch ./"sub proj" master &&
706 git subtree merge --prefix="sub dir" FETCH_HEAD &&
707 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
709 test_create_commit "$subtree_test_count/sub proj" sub3 &&
710 test_create_commit "$subtree_test_count" "sub dir"/main-sub3 &&
712 cd "$subtree_test_count/sub proj" &&
713 git fetch .. subproj-br &&
716 test_create_commit "$subtree_test_count/sub proj" sub4 &&
718 cd "$subtree_test_count" &&
719 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
721 test_create_commit "$subtree_test_count" "sub dir"/main-sub4 &&
723 cd "$subtree_test_count" &&
724 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
727 cd "$subtree_test_count/sub proj" &&
728 git fetch .. subproj-br &&
732 cd "$subtree_test_count" &&
733 git subtree pull --prefix="sub dir" ./"sub proj" master &&
741 chks_sub=$(cat <<TXT | sed '\''s,^,sub dir/,'\''
749 chkms_sub=$(cat <<TXT | sed '\''s,^,sub dir/,'\''
754 # main-sub?? and /"sub dir"/main-sub?? both change, because those are the
755 # changes that were split into their own history. And "sub dir"/sub?? never
756 # change, since they were *only* changed in the subtree branch.
757 allchanges=$(git log --name-only --pretty=format:"" | sort | sed "/^$/d") &&
758 expected=''"$(cat <<TXT | sort
765 check_equal "$allchanges" "$expected"
770 test_expect_success
'make sure the --rejoin commits never make it into subproj' '
771 subtree_test_create_repo "$subtree_test_count" &&
772 subtree_test_create_repo "$subtree_test_count/sub proj" &&
773 test_create_commit "$subtree_test_count" main1 &&
774 test_create_commit "$subtree_test_count/sub proj" sub1 &&
776 cd "$subtree_test_count" &&
777 git fetch ./"sub proj" master &&
778 git subtree add --prefix="sub dir" FETCH_HEAD
780 test_create_commit "$subtree_test_count" "sub dir"/main-sub1 &&
781 test_create_commit "$subtree_test_count" main2 &&
782 test_create_commit "$subtree_test_count/sub proj" sub2 &&
783 test_create_commit "$subtree_test_count" "sub dir"/main-sub2 &&
785 cd "$subtree_test_count" &&
786 git fetch ./"sub proj" master &&
787 git subtree merge --prefix="sub dir" FETCH_HEAD &&
788 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
790 test_create_commit "$subtree_test_count/sub proj" sub3 &&
791 test_create_commit "$subtree_test_count" "sub dir"/main-sub3 &&
793 cd "$subtree_test_count/sub proj" &&
794 git fetch .. subproj-br &&
797 test_create_commit "$subtree_test_count/sub proj" sub4 &&
799 cd "$subtree_test_count" &&
800 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
802 test_create_commit "$subtree_test_count" "sub dir"/main-sub4 &&
804 cd "$subtree_test_count" &&
805 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
808 cd "$subtree_test_count/sub proj" &&
809 git fetch .. subproj-br &&
813 cd "$subtree_test_count" &&
814 git subtree pull --prefix="sub dir" ./"sub proj" master &&
815 check_equal "$(git log --pretty=format:"%s" HEAD^2 | grep -i split)" ""
820 test_expect_success
'make sure no "git subtree" tagged commits make it into subproj' '
821 subtree_test_create_repo "$subtree_test_count" &&
822 subtree_test_create_repo "$subtree_test_count/sub proj" &&
823 test_create_commit "$subtree_test_count" main1 &&
824 test_create_commit "$subtree_test_count/sub proj" sub1 &&
826 cd "$subtree_test_count" &&
827 git fetch ./"sub proj" master &&
828 git subtree add --prefix="sub dir" FETCH_HEAD
830 test_create_commit "$subtree_test_count" "sub dir"/main-sub1 &&
831 test_create_commit "$subtree_test_count" main2 &&
832 test_create_commit "$subtree_test_count/sub proj" sub2 &&
833 test_create_commit "$subtree_test_count" "sub dir"/main-sub2 &&
835 cd "$subtree_test_count" &&
836 git fetch ./"sub proj" master &&
837 git subtree merge --prefix="sub dir" FETCH_HEAD &&
838 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
840 test_create_commit "$subtree_test_count/sub proj" sub3 &&
841 test_create_commit "$subtree_test_count" "sub dir"/main-sub3 &&
843 cd "$subtree_test_count/sub proj" &&
844 git fetch .. subproj-br &&
847 test_create_commit "$subtree_test_count/sub proj" sub4 &&
849 cd "$subtree_test_count" &&
850 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
852 test_create_commit "$subtree_test_count" "sub dir"/main-sub4 &&
854 cd "$subtree_test_count" &&
855 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
858 cd "$subtree_test_count/sub proj" &&
859 git fetch .. subproj-br &&
863 cd "$subtree_test_count" &&
864 git subtree pull --prefix="sub dir" ./"sub proj" master &&
866 # They are meaningless to subproj since one side of the merge refers to the mainline
867 check_equal "$(git log --pretty=format:"%s%n%b" HEAD^2 | grep "git-subtree.*:")" ""
876 test_expect_success
'make sure "git subtree split" find the correct parent' '
877 subtree_test_create_repo "$subtree_test_count" &&
878 subtree_test_create_repo "$subtree_test_count/sub proj" &&
879 test_create_commit "$subtree_test_count" main1 &&
880 test_create_commit "$subtree_test_count/sub proj" sub1 &&
882 cd "$subtree_test_count" &&
883 git fetch ./"sub proj" master &&
884 git subtree add --prefix="sub dir" FETCH_HEAD
886 test_create_commit "$subtree_test_count/sub proj" sub2 &&
888 cd "$subtree_test_count" &&
889 git fetch ./"sub proj" master &&
890 git branch subproj-ref FETCH_HEAD &&
891 git subtree merge --prefix="sub dir" FETCH_HEAD
893 test_create_commit "$subtree_test_count" "sub dir"/main-sub1 &&
895 cd "$subtree_test_count" &&
896 git subtree split --prefix="sub dir" --branch subproj-br &&
898 # at this point, the new commit parent should be subproj-ref, if it is
899 # not, something went wrong (the "newparent" of "master~" commit should
900 # have been sub2, but it was not, because its cache was not set to
902 check_equal "$(git log --pretty=format:%P -1 subproj-br)" "$(git rev-parse subproj-ref)"
907 test_expect_success
'split a new subtree without --onto option' '
908 subtree_test_create_repo "$subtree_test_count" &&
909 subtree_test_create_repo "$subtree_test_count/sub proj" &&
910 test_create_commit "$subtree_test_count" main1 &&
911 test_create_commit "$subtree_test_count/sub proj" sub1 &&
913 cd "$subtree_test_count" &&
914 git fetch ./"sub proj" master &&
915 git subtree add --prefix="sub dir" FETCH_HEAD
917 test_create_commit "$subtree_test_count/sub proj" sub2 &&
919 cd "$subtree_test_count" &&
920 git fetch ./"sub proj" master &&
921 git subtree merge --prefix="sub dir" FETCH_HEAD
923 test_create_commit "$subtree_test_count" "sub dir"/main-sub1 &&
925 cd "$subtree_test_count" &&
926 git subtree split --prefix="sub dir" --branch subproj-br
928 mkdir "$subtree_test_count"/"sub dir2" &&
929 test_create_commit "$subtree_test_count" "sub dir2"/main-sub2 &&
931 cd "$subtree_test_count" &&
933 # also test that we still can split out an entirely new subtree
934 # if the parent of the first commit in the tree is not empty,
935 # then the new subtree has accidently been attached to something
936 git subtree split --prefix="sub dir2" --branch subproj2-br &&
937 check_equal "$(git log --pretty=format:%P -1 subproj2-br)" ""
942 test_expect_success
'verify one file change per commit' '
943 subtree_test_create_repo "$subtree_test_count" &&
944 subtree_test_create_repo "$subtree_test_count/sub proj" &&
945 test_create_commit "$subtree_test_count" main1 &&
946 test_create_commit "$subtree_test_count/sub proj" sub1 &&
948 cd "$subtree_test_count" &&
949 git fetch ./"sub proj" master &&
950 git branch sub1 FETCH_HEAD &&
951 git subtree add --prefix="sub dir" sub1
953 test_create_commit "$subtree_test_count/sub proj" sub2 &&
955 cd "$subtree_test_count" &&
956 git fetch ./"sub proj" master &&
957 git subtree merge --prefix="sub dir" FETCH_HEAD
959 test_create_commit "$subtree_test_count" "sub dir"/main-sub1 &&
961 cd "$subtree_test_count" &&
962 git subtree split --prefix="sub dir" --branch subproj-br
964 mkdir "$subtree_test_count"/"sub dir2" &&
965 test_create_commit "$subtree_test_count" "sub dir2"/main-sub2 &&
967 cd "$subtree_test_count" &&
968 git subtree split --prefix="sub dir2" --branch subproj2-br &&
971 git log --pretty=format:"commit: %H" | join_commits |
973 while read commit a b; do
974 test_debug "echo Verifying commit $commit"
975 test_debug "echo a: $a"
976 test_debug "echo b: $b"
986 test_expect_success
'push split to subproj' '
987 subtree_test_create_repo "$subtree_test_count" &&
988 subtree_test_create_repo "$subtree_test_count/sub proj" &&
989 test_create_commit "$subtree_test_count" main1 &&
990 test_create_commit "$subtree_test_count/sub proj" sub1 &&
992 cd "$subtree_test_count" &&
993 git fetch ./"sub proj" master &&
994 git subtree add --prefix="sub dir" FETCH_HEAD
996 test_create_commit "$subtree_test_count" "sub dir"/main-sub1 &&
997 test_create_commit "$subtree_test_count" main2 &&
998 test_create_commit "$subtree_test_count/sub proj" sub2 &&
999 test_create_commit "$subtree_test_count" "sub dir"/main-sub2 &&
1001 cd $subtree_test_count/"sub proj" &&
1002 git branch sub-branch-1 &&
1004 git fetch ./"sub proj" master &&
1005 git subtree merge --prefix="sub dir" FETCH_HEAD
1007 test_create_commit "$subtree_test_count" "sub dir"/main-sub3 &&
1009 cd "$subtree_test_count" &&
1010 git subtree push ./"sub proj" --prefix "sub dir" sub-branch-1 &&
1012 git checkout sub-branch-1 &&
1013 check_equal "$(last_commit_message)" "sub dir/main-sub3"
1018 # This test covers 2 cases in subtree split copy_or_skip code
1019 # 1) Merges where one parent is a superset of the changes of the other
1020 # parent regarding changes to the subtree, in this case the merge
1021 # commit should be copied
1022 # 2) Merges where only one parent operate on the subtree, and the merge
1023 # commit should be skipped
1025 # (1) is checked by ensuring subtree_tip is a descendent of subtree_branch
1026 # (2) should have a check added (not_a_subtree_change shouldn't be present
1027 # on the produced subtree)
1029 # Other related cases which are not tested (or currently handled correctly)
1030 # - Case (1) where there are more than 2 parents, it will sometimes correctly copy
1031 # the merge, and sometimes not
1032 # - Merge commit where both parents have same tree as the merge, currently
1033 # will always be skipped, even if they reached that state via different
1038 test_expect_success
'subtree descendant check' '
1039 subtree_test_create_repo "$subtree_test_count" &&
1040 test_create_commit "$subtree_test_count" folder_subtree/a &&
1042 cd "$subtree_test_count" &&
1045 test_create_commit "$subtree_test_count" folder_subtree/0 &&
1046 test_create_commit "$subtree_test_count" folder_subtree/b &&
1047 cherry=$(cd "$subtree_test_count"; git rev-parse HEAD) &&
1049 cd "$subtree_test_count" &&
1052 test_create_commit "$subtree_test_count" commit_on_branch &&
1054 cd "$subtree_test_count" &&
1055 git cherry-pick $cherry &&
1056 git checkout master &&
1057 git merge -m "merge should be kept on subtree" branch &&
1058 git branch no_subtree_work_branch
1060 test_create_commit "$subtree_test_count" folder_subtree/d &&
1062 cd "$subtree_test_count" &&
1063 git checkout no_subtree_work_branch
1065 test_create_commit "$subtree_test_count" not_a_subtree_change &&
1067 cd "$subtree_test_count" &&
1068 git checkout master &&
1069 git merge -m "merge should be skipped on subtree" no_subtree_work_branch &&
1071 git subtree split --prefix folder_subtree/ --branch subtree_tip master &&
1072 git subtree split --prefix folder_subtree/ --branch subtree_branch branch &&
1073 check_equal $(git rev-list --count subtree_tip..subtree_branch) 0